Alright, I am making an audio system, and I wanna make sure it works with printing, but instead, it prints "nil" Okay, so here's my client part of the script:
local SoundService = game:GetService("SoundService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local revent = ReplicatedStorage.SoundEvent local frame = script.Parent local song1 = frame.song1 local cooldown = 7 local debounce = false local song1id = 2518263386--This is what I want the normal script to print just to test. local player = game.Players.LocalPlayer song1.MouseButton1Click:Connect(function(player,song1id) if not debounce then debounce = true revent:FireServer(player,song1id)--I fire the songid too. wait(cooldown) debounce = false end end)
That's the localscript, and this below is the actual script:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local revent = ReplicatedStorage.SoundEvent local soundbox = script.Parent.Sound local audio = script.Parent.Sound.SoundId local function test(player,song1id) audio = song1id print(song1id) end revent.OnServerEvent:Connect(test)
When I click the gui button, instead I just get "nil", can somebody tell me why?
The problem is, GUIObject.MouseButton1Click
doesn't call the connecting function with anything.. however, in your (LocalScript) code on line 12, the function that handles the MouseButton1Click
has 2 arguments, therefore, both arguments will be nil
once the event fires.
also, whenever a LocalScript does RemoteEvent:FireServer
, the OnServerEvent
handling functions will be called with the player that called FireServer
and then all other arguments that you pass to it.. therefore, you don't need to pass player
to FireServer
, roblox automatically does it for you
EDIT:
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage") local revent = ReplicatedStorage.SoundEvent local frame = script.Parent local song1 = frame.song1 local cooldown = 7 local debounce = false local song1id = 2518263386--This is what I want the normal script to print just to test. local player = game.Players.LocalPlayer song1.MouseButton1Click:Connect(function() if not debounce then debounce = true revent:FireServer(song1id)--I fire the songid too. wait(cooldown) debounce = false end end)
Server Side
local ReplicatedStorage = game:GetService("ReplicatedStorage") local revent = ReplicatedStorage.SoundEvent local soundbox = script.Parent.Sound local audio = script.Parent.Sound.SoundId function test(player,song1id) audio = song1id print(song1id) end revent.OnServerEvent:Connect(test)