Closed axisdadev closed 1 year ago
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();
}
}
Still has the same issue, ServiceName must be a string; got table
At the end of the module are you returning MusicService?
return MusicService
Yes i am.
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.
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 `
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 \`\
)
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 "."
.
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()}, } `