Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

ServiceName must be a string; got table #228

Closed
axisdadev opened this issue Jul 12, 2023 · 8 comments
Closed

ServiceName must be a string; got table #228

axisdadev opened this issue Jul 12, 2023 · 8 comments

Comments

@axisdadev
Copy link

Followed the tutorial on the docs and YouTube video followed it thoroughly, not sure whats happening here but every time I call the service I get this error.

ServiceName must be a string; got table

I'm not sure what really could be causing this,

`local Knit = require(game.ReplicatedStorage.Packages.Knit)
local Signal = require(Knit.Util.Signal)

local MusicService = Knit.CreateService {
Name = "MusicService",
Client = {SoundtrackUpdate = Signal.new()},
}
`

@royce-mathew
Copy link

You don't have to require the signal module to create a signal. You can create a signal directly by doing

local Knit = require(game:GetService("ReplicatedStorage"):WaitForChild("Packages").Knit)
local MusicService = Knit.CreateService {
 Name = "MusicService",
 Client = {
  SoundtrackUpdate = knit.CreateSignal();
 }
}

@axisdadev axisdadev reopened this Jul 13, 2023
@axisdadev
Copy link
Author

Still has the same issue, ServiceName must be a string; got table

@royce-mathew
Copy link

royce-mathew commented Jul 13, 2023

At the end of the module are you returning MusicService?

return MusicService

@axisdadev
Copy link
Author

Yes i am.

@axisdadev axisdadev reopened this Jul 13, 2023
@royce-mathew
Copy link

royce-mathew commented Jul 13, 2023

Are you able to post the module script here? Also, instead of doing close with comment, you can just do a normal comment and then close this issue when it's fixed.

@axisdadev axisdadev closed this as not planned Won't fix, can't repro, duplicate, stale Jul 13, 2023
@axisdadev axisdadev reopened this Jul 13, 2023
@axisdadev
Copy link
Author

axisdadev commented Jul 13, 2023

Sorry, I accidentally keep clicking the wrong button.

Anyways here is my code.

`
local Knit = require(game.ReplicatedStorage.Packages.Knit)
local Signal = require(Knit.Util.Signal)

local MusicService = Knit.CreateService {
Name = "MusicService",
Client = {
SoundtrackUpdate = Knit.CreateSignal();
}
}

function MusicService:KnitInit()
print(script.Name .. ": Initalized")
end

function MusicService:KnitStart()
print(script.Name .. ": Started")
end

-- code --

function MusicService:ServerPlaySoundtrack(soundTrackObject: Sound)
self.CurrentSoundtrack = soundTrackObject
soundTrackObject:Play()
soundTrackObject.Volume = 0
self.Client.SoundtrackUpdate:Fire(soundTrackObject)
end

function MusicService.Client:GetCurrentPlayingTrack()
local currentSoundtrack = self.CurrentSoundtrack
return currentSoundtrack
end

function MusicService:SetTrackPosition(soundTrackObject: Sound)
soundTrackObject.TimePosition = self.CurrentSoundtrack.TimePosition
end

return MusicService
`

@royce-mathew
Copy link

royce-mathew commented Jul 13, 2023

You cannot describe functions inside the client table. Instead of doing

function MusicService.Client:GetCurrentPlayingTrack()
  local currentSoundtrack = self.CurrentSoundtrack
  return currentSoundtrack
end

You could instead, create a remote property for the current soundtrack and use the following documentation. https://sleitnick.github.io/Knit/docs/services#properties

(Also, you can embed code on Github by enclosing your code inside ```lua and closing it with another set of ```)

@wrello
Copy link

wrello commented Aug 4, 2023

Hey, if you haven't solved this yet, I was able to reproduce the error with Knit.GetService({}).

You might possibly be using Knit:GetService(serviceName) instead of Knit.GetService(serviceName) somewhere in your code base. It's an error I've ran into a few times myself and can be quite confusing if you don't notice the extra dot making it a ":" instead of a ".".

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants