Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago
Edited 4 years ago

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?

0
Take out the player argument from FireServer()? jalbraek 29 — 4y
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. VoidKeyword 111 — 4y
0
Now it prints my username @jalbraek VoidKeyword 111 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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)
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. VoidKeyword 111 — 4y
0
lemme edit my answer to show you. User#23252 26 — 4y
0
So you're saying I don't put the parentheses in the function part? VoidKeyword 111 — 4y
0
Huh, I guess that is the case. Thanks! VoidKeyword 111 — 4y
0
what do you mean? User#23252 26 — 4y
Ad

Answer this question