Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Remote Event prints "nil" instead of IntValue I fired with it?

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?

4 comments

0

Take out the player argument from FireServer()?

0

A lot of the people who I talked to yesterday about something similar said player is always supposed to be there, and be first. I might make a logs system too later, so I'm keeping it.

0

Now it prints my username @jalbraek

1 answer

✓ Accepted answer

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)

5 comments

0

So what are you saying I need to do? I already placed song1id in both parentheses in the localscript and also did it in the other script.

0

lemme edit my answer to show you.

0

So you're saying I don't put the parentheses in the function part?

0

Huh, I guess that is the case. Thanks!

0

what do you mean?

This discussion is preserved as it was. New answers, comments, and votes are closed.