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

Roblox remote event passing in int and getting nil?

Asked by 6 years ago

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

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

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)
0
Thanks man, didn't realize parameter for player doesn't transfer over. TheGreatSailor 20 — 6y
Ad

Answer this question