Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make my script give leaderstat value only to player who touched the part, not all server?

Asked by 2 years ago

Explaination: Ok so i made a portals and scripts what teleporting player to next stage and giving to player leaderstats +1 stage completed. So, we have tested that system with my friend, and figured that script gives +1 stage completed to all players on server. So im wanna change it to make give +1 stage only for those players, who touched portal script.

Scripts:

Local StarterPack scripts(they are almost same, just part what player touching changed):

local touchName = "Stages"
    local rs = game:GetService("ReplicatedStorage")

    local touchEvent = rs:WaitForChild('TouchEvent')
    local portal = workspace.FirstStage.FrostPartal.PortalPart
    local Debounce = false

    portal.Touched:Connect(function()
            if(Debounce == false) then
                    Debounce = true 
                    touchEvent:FireServer() 
                    wait(1) 
                    Debounce = false
end)

Server Leaderstats Script:

local function onPlayerJoin(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player


    local start = Instance.new("IntValue")
    start.Name = "Stages"
    start.Value = 0
    start.Parent = leaderstats
end

game.Players.PlayerAdded:Connect(onPlayerJoin)

local touchName = "Stages"
local rs = game:GetService("ReplicatedStorage")

local touchEvent = rs:WaitForChild('TouchEvent')



touchEvent.OnServerEvent:Connect(function(plr)

    plr.leaderstats[touchName].Value = plr.leaderstats[touchName].Value +1

    wait(1)




end)

Answer this question