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

(HELP PLEASE) How to make my scripts giving +1 stage only for player who touched portal?

Asked by 3 years ago
Edited 3 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)

1 answer

Log in to vote
0
Answered by 3 years ago

First of all, why put the local script in starterpack scripts instead of in the workspace? Make a script in the workspace and parent it to the portal and insert this script here:

local DB = false

script.Parent.Touched:Connect(function()
if DB == false then
DB = true
game.ReplicatedStorage.touchEvent:FireServer()
wait(1)
DB = false
end

end)

After that, insert a script into ServerScriptService and input this code here:

game.ReplicatedStorage.touchEvent.OnServerEvent:Connect(function(plr)
plr.leaderstats.Stages = plr.leaderstats.Stages + 1

end)
Ad

Answer this question