Hello !
So as the title says, it seems that my remoteEvent isn’t firing/the client doesn’t get fired. Here’s my code
Server side:
remote1.OnServerEvent:Connect(function(player, player2, amount)
print(game.Players:FindFirstChild(player2).Name)
remote2:FireClient(game.Players:FindFirstChild(player2), amount)
print("done")
end)
Client:
remote2.OnClientEvent:Connect(function(amount)
print("arrived on client")
label.Text = amount
end)
In the output:
PachaMan212 (username of player2)
done
I checked, and the remote variables are correct.
I found some post about similar issues on deforum but none got solved.
I also restarted studio
Anybody knows how to solve this ?
make sure you firing the first remote that sends the player to the server, make sure a player is found, make sure to add a :WaitForChild() for every remote, this is only needed if you’re firing or recieving a signal from the client
yes, the first remote is fired, as if it wasn’t, nothing would print
A player is found as it prints it’s username
I already added a WaitForChild()
Basically, you’re trying to retrieve the player2 on the client (which I assume is the LocalPlayer), but when you’re firing the client, the first argument in the event determines which players client to fire, it is not received on the client by default. Just try removing the player2 parameter from the OnClientEvent function.
New Client Script
remote2.OnClientEvent:Connect(function(amount)
print("arrived on client")
label.Text = amount
end)
If you want to get the LocalPlayer, you can reference it with game.Players.LocalPlayer
.
Another problem I found is that maybe the player doesn’t exist, so you would have to check if the player exists to prevent errors. What I would do is create a variable that called FindFirstChild to the players name and make an if statement on that.
New Server Script
remote1.OnServerEvent:Connect(function(player, player2, amount)
local plr2 = game.Players:FindFirstChild(player2)
if plr2 then
print(plr2.Name)
remote2:FireClient(plr2, amount)
print("done")
end
end)
1 Like
You have something here:
remote2.OnClientEvent:Connect(function(player2, amount)
player2 is the amount and amount is nil
when recieving something on the client no player argument is passed
I tried, and still, the client doesn’t print anything, even if the server prints done.
I actually want to get player and not player2 from the client, I just messed up this
Quick question is there something actually firing the event to begin with?
i don’t know what do you mean with Player2 but if you mean with it the LocalPlayer here is the fix
Client Side:
remote2.OnClientEvent:Connect(function(amount)
print("arrived on client")
label.Text = amount
end)
Server Side :
remote1.OnServerEvent:Connect(function(player, amount)
remote2:FireClient(player, amount)
end)
Yes there is, if there wasn’t the server wouldn’t print “done”
is the client side on startergui or playerscripts or anywhere inside the player?
What’re the values that you’re passing through the FireServer function?
there basically is “player” giving “amount” of money to “player 2”
Here’s how it works:
- “player” click a button to give “amount” of money to “player2”
- “player2” receive the money and fire the server with remote1, then the server fire “player” with remote2 and deduce his money
I do it that way to prevent people from cheating with Remote spy
1 Like
It’s in startergui, but how does it changes anything ?
wait(1)
remote1.OnServerEvent:Connect(function(player, amount)
remote2:FireClient(player, amount)
end)
This is what i got, but I need the server to fire player2
sorry wrong script XD:
wait(1)
remote2.OnClientEvent:Connect(function(amount)
print(“arrived on client”)
label.Text = amount
end)
it still is exactly the same script as the one I have
so, remove the wait time on the client side one
add a :WaitForChild() for the remote varialbe and it should be fixed
player2 is an instance, and amount is a number
Already have a waitforchild() too