I’ve been working on this teleport script, though while testing no more players will be teleported after a player hits the part.
Script |
local Spawns = game.Workspace.Lobby.Map:FindFirstChild("Spawns"):GetChildren()
local Teleports = game.Workspace.Stages:FindFirstChild("Teleports")
local Debounce = false
script.Parent.Touched:Connect(function(Hit)
if Debounce then return end
Debounce = true
local PlayerStats = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Hit.Parent:FindFirstChild("Humanoid") and PlayerStats.leaderstats.XP.Value >= 0 then
local Player = Hit.Parent
Player.Torso.CFrame = Spawns[math.random(1, #Spawns)].CFrame
PlayerStats.leaderstats.XP.Value = PlayerStats.leaderstats.XP.Value + 10
if PlayerStats.DoubleXP.Value == true then
PlayerStats.leaderstats.XP.Value = PlayerStats.leaderstats.XP.Value + 10
wait(1)
Debounce = false
end
end
end)
At first glance, I would try splitting the ‘if hit.Parent’ and Playerstats conditional into two separate conditionals and putting the ;Getplayer from character’ call in between them and see if that works.
It’s okay, though I’m kinda confused on the way the “Getplayer from Character” is formatted between the two conditionals. If possible, could you show the way it should be formatted please.
You set your Debounce back to false inside your Double XP conditional check, why is probably why it’s not working for other players since it’s still set to true
try this:
local Spawns = game.Workspace.Lobby.Map:FindFirstChild("Spawns"):GetChildren()
local Teleports = game.Workspace.Stages:FindFirstChild("Teleports")
local Debounce = false
script.Parent.Touched:Connect(function(Hit)
if Debounce then return end
Debounce = true
local PlayerStats = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Hit.Parent:FindFirstChild("Humanoid") and PlayerStats.leaderstats.XP.Value >= 0 then
local Player = Hit.Parent
Player.Torso.CFrame = Spawns[math.random(1, #Spawns)].CFrame
PlayerStats.leaderstats.XP.Value = PlayerStats.leaderstats.XP.Value + 10
if PlayerStats.DoubleXP.Value == true then
PlayerStats.leaderstats.XP.Value = PlayerStats.leaderstats.XP.Value + 10
end
wait(1)
Debounce = false
end
end)