You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Make so when a player touches a part, the script only gives one win instead of repeatingly giving wins.
What is the issue? Include screenshots / videos if possible!
Its giving 10-20 wins
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Original Script
amnt = 1 --how much you get for it
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("leaderstats")
if (stats~=nil) then
local score = stats:findFirstChild("Wins")
if (score~=nil) then
score.Value = score.Value + amnt
end
end
end
script.Parent:remove()
end
end
script.Parent.Touched:connect(onTouched)
i tried local script:disable instead of delete parent, but couldn’t figure out how to make it still work for the second round. i think it needs to use module scripts/local events?
if I don’t disable it it gives 10-20 wins.
the part is overlapped by an exact clone of exact size and position that has a teleport script inside. (tp within a place, btw)
local debounce = true
script.Parent.Touched:Connect(funtion(hit)
if debounce == true then
debounce = false
print(“hit 1 time”)
end
end)
amnt = 1 --how much you get for it
function onTouched(part)
local h = part.Parent:findFirstChild(“Humanoid”)
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild(“leaderstats”)
if (stats~=nil) then
local score = stats:findFirstChild(“Wins”)
if (score~=nil) then
score.Value = score.Value + amnt
end
end
end
local script:disable
end
end
Changing the property script.Disabled will disable the script. The script can be disabled itself, but once disabled, the script won’t run (so it won’t enable itself, neither.)
local db = true
function onTouched(part)
if db then
db = false
game.ReplicatedStorage.RemoteEvent:FireServer(part)
end
end
script.Parent.Touched:Connect(onTouched)
Now type the following code in the Server Script
function server(plr,part)
amnt = 1 --how much you get for it
local h = part.Parent:findFirstChild("Humanoid")
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("leaderstats")
if (stats~=nil) then
local score = stats:findFirstChild("Wins")
if (score~=nil) then
score.Value = score.Value + amnt
end
end
end
end
end
end
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(server)