Teleport script giving more "XP" than expected after teleport

I’ve been trying to script a portal that gives the player “XP” after they complete a mini obstacle course.

Currently, I have been using this script, though more than 20 “XP” is obtained after hitting the teleport part.

Attempt 1

Script

You do not have a debounce in your touched event, Touched fires multiple times for what seems to be once because of how many physics interactions that happen on that part

A debounce in its simplest terms is this

local deb = false

part.Touched:Connect(function(hit)
    if deb then return end
    deb = true
    --Your code
    wait(1) -- Waits a second
    deb = false
end)

This only allows the code to run once per second if it’s being touched multiple times because of that boolean variable

Judging from what you have, you may need to contain these in a dictionary rather than a bool variable

1 Like