What do you want to achieve?
I want to add a win to the player’s win leaderstat when the player touches a part.
What is the issue?
I made a script to do this however I see no wins added to the leaderstat nor an error in the console
What solutions have you tried so far?
I have tried this script:
Client
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("AddWIn")
script.Parent.Touched:Connect(function(hit)
local plr = hit.Parent:FindFirstChild("Humanoid")
RemoteEvent:FireServer(plr)
end)
Server
local AddWinevent = game:GetService("ReplicatedStorage"):WaitForChild("AddWIn")
AddWinevent.OnServerEvent:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local wins = leaderstats:WaitForChild("Wins")
if wins.Value == 18 then --make sure the player is the last stage
wins.Value = wins.Value + 1
else
plr:Kick("Anticheat detection!")
end
end)
I tried finding solutions on the devforum but found none.
Please help me.
You should have checkpoints and wins in a different value since it doesn’t really make much sense. You should compare 18 to the checkpoint and not wins, so I would recommend making a value called checkpoint.
I made this the script and I am stage 18 in-game however the script fails to add a win to my win leaderstat.
local AddWinevent = game:GetService("ReplicatedStorage"):WaitForChild("AddWIn")
AddWinevent.OnServerEvent:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local wins = leaderstats:WaitForChild("Wins")
local stage = leaderstats:WaitForChild("Stage")
if stage.Value == 18 then --make sure the player is the last stage
wins.Value = wins.Value + 1
else
plr:Kick("Anticheat detection!")
end
end)
I see a couple of things wrong. Handle the .Touched event on the server as you can simply get the player and update their leaderstats right there. Also since you are handling this on the client you don’t need to send a player as an argument since it already does that so you can remove the plr (also you are sending the humanoid not the player) in the client script.
local part = game.Workspace.Stuff.WINPART
part.Touched:Connect(function(hit)
local plr = hit.Parent:FindFirstChild("Humanoid")
local leaderstats = plr:WaitForChild("leaderstats")
local wins = leaderstats:WaitForChild("Wins")
local stage = leaderstats:WaitForChild("Stage")
if stage.Value == 18 then
wins.Value = wins.Value + 1
else
plr:Kick("Anticheat Detection.")
end
end)
local part = game.Workspace.Stuff.WINPART
part.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if not plr then return end
local leaderstats = plr:WaitForChild("leaderstats")
local wins = leaderstats:WaitForChild("Wins")
local stage = leaderstats:WaitForChild("Stage")
if stage.Value == 18 then
wins.Value = wins.Value + 1
else
plr:Kick("Anticheat Detection.")
end
end)