Hello everyone! I'm trying to increase the security of my servers to prevent admin abusing by adding a NumberValue called "Faults" into the player's folder called "leaderstats". I made a ScreenGUI which only me can use to add a fault to the player who deserved it. I use a RemoteEvent in the ReplicatedStorage to communicate the ServerScript which increases 1 in the Faults value and the LocalScript that calls the ServerScript with the player's name. The matter is when the ServerScript tries to acces the leaderstats folder. The output says "attempt to index nil leaderstats". LocalScript:
local remote = game.ReplicatedStorage:WaitForChild("Remote") remote:FireServer(script.Parent.Parent.PlayerNameText.Text)
ServerScript:
local remote = game.ReplicatedStorage:WaitForChild("Remote") remote.OnServerEvent:Connect(function(player, nam) local Player = game.Players:FindFirstChild(nam) Player.leaderstats.Faults.Value = Player.leaderstats.Faults.Value + 1 end)
Can someone help the ServerScript access the leaderstats Folder?
You would need to add a :WaitForChild() because by the time the script runs the Leaderstats are not yet loaded. Here is what you should have.
Local Script
local remote = game.ReplicatedStorage:WaitForChild("Remote") remote:FireServer(script.Parent.Parent.PlayerNameText.Text)
local remote = game.ReplicatedStorage:WaitForChild("Remote") remote.OnServerEvent:Connect(function(player, nam) local Player = game.Players:FindFirstChild(nam) Player:WaitForChild('leaderstats').Faults.Value = Player.leaderstats.Faults.Value + 1 end)
According the error Player
is nil, so check why Player
is nil
Ok, So When You Send The Player Parameter From The Local Script When You FireServer() It Automatically Sends The Player Who Fireed The Server As An "Instance", Hence Sending The Actual Player. So, You Don't Need To Find The Player You Can Just Do
player:WaitForChild('leaderstats').Faults.Value = Player.leaderstats.Faults.Value + 1