'problem with event parameters / arguments. (Roblox Studio)
Basically I have a code that gets fired to a localscript in all players. The speaker / player argument is used to make sure the event is recieved by the correct reciever, and the "allow" argument is a boolean value used for later code. (Don't think about that part).
This is the :FireClient Script
1 game.ReplicatedStorage.AllowDisallow:FireClient(speaker, true)
This is the reciever / localscript
1 game.ReplicatedStorage.AllowDisallow.OnClientEvent:Connect(function(player, allow)
2 if not player.Name == game.Players.LocalPlayer.Name then return end
Error:
attempt to index boolean with 'Name'
My thought is that it erases the player parameter and switches it with the 'allow' bool value. I have tried searching this issue up on google, but I did not find a clear answer.
OTHER INFORMATION:
- There's an event in ReplicatedStorage, which is the one im using.
- It's called "AllowDisallow". Don't think too much about the name.
- The 'allow' argument should be a bool value, and the "player" should be the player.
Sincerely, Mathe
Solution 1:[1]
The error is telling you that the player
variable in the LocalScript is a boolean, not a Player object.
When you call a RemoteEvent's FireClient function, the first argument indicates which player it is going to, and all the rest are provided as the arguments in the OnClientEvent callback. For example,
-- if the server calls...
RemoteEvent:FireClient(player, a, b, c)
-- the client will receive...
RemoteEvent.OnClientEvent:Connect(function(a, b, c) end)
You just need to update your receiver LocalScript so that the arguments reflect what the server is providing. Then you can remove the LocalPlayer safety check, because the OnClientEvent only fires for the LocalPlayer.
local allowDisallow = game.ReplicatedStorage.AllowDisallow
allowDisallow.OnClientEvent:Connect(function(allow)
-- do some stuff
end)
Solution 2:[2]
try to print out the arguments in the server event and check whats wrong
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kylaaa |
Solution 2 | Whoman |