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

Roblox remote event passing in int and getting nil?

In the script server side I have:

local hoverEnterAmmo = game.ReplicatedStorage.HoverEnterAmmo
num = script.Parent.AmmoNumStored
math.randomseed(tick())
num.Value = math.random(1,50)

script.Parent.ClickDetector.MouseHoverEnter:connect(function(Player)
	print(num.Value)
	hoverEnterAmmo:FireClient(Player, num.Value)
end)

In the local script I have:

local hoverLeaveAmmo = game.ReplicatedStorage:WaitForChild("HoverLeaveAmmo")
hoverEnterAmmo.OnClientEvent:connect(function(player, num)
	textForHover.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y + 15)
	textForHover.Visible = true
	print(num.." "..num)
	totalAmmo = totalAmmo 
	lowerValueOnScreen()
end)

Not sure I'm doing it correctly at all, when I print(num) in the local script I get nil what am I doing wrong? Thanks for your help it's much appreciated!

1 answer

✓ Accepted answer

Even though the paramater for the player is required for FireClient, this does not transfer across to the OnClientEvent in the local script. So in your local script, the player argument would be num and the num argument would be nil. So to fix this, all you should need to do is remove the player argument in the local script:

hoverEnterAmmo.OnClientEvent:Connect(function(num)

1 comment

0

Thanks man, didn't realize parameter for player doesn't transfer over.

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