How to fix this Add Win Script?

  1. What do you want to achieve?
    I want to add a win to the player’s win leaderstat when the player touches a part.

  2. 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

  3. 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.

1 Like

You’re comparing how many wins a player has to get a win. This will only work if they have exactly 18 wins

1 Like

Yes as that is the last stage in my obby. I don’t want cheaters to get a win by using fly hacks if they are not stage 18.

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.

1 Like

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.

1 Like

The client does NOT detect .Touched event

1 Like

Yeah, I was thinking that, but I couldn’t remember correctly since I haven’t used it in a while.

2 Likes

How can I detect which player stepped on the part. I seemed to have forgotten :sweat_smile:

With a server script, just put both script together without the remote connecting them, make them together basically

1 Like

You got the player correctly, now just add the wins in the touched event in a server script

1 Like

Yes I did that

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)

but it says
image

That’s the wrong code, lemme fix it for you rq

1 Like

Okay thank you so much!

[3_0 chara limit]

1 Like

Here is the code

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)
1 Like

You basically saying player is a humanoid so you’ll need define player

1 Like

Uhhhh I want to make it so that it only gives 1 win not multiple wins

Video post #20

The video doesn’t work.
Charrrrssss

1 Like

Add a debounce, it will fix it

1 Like

Oh no ima reupload