Made this function to teleport/reward you, but the function keeps stalling.
is this a syntax error or did I place the “reward” to close to the teleport script?
local Respawner = game.Workspace.respawner
script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
local Tele = Player.Character:FindFirstChild("Tele")
if not Tele then return end
if not Tele.Value then
Tele.Value = true
Player.Character.HumanoidRootPart.CFrame = Respawner.CFrame + Vector3.new(0, 5, 0)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 85
wait(3)
Tele.Value = false
end
end
end)
Well first of all your not checking if it’s a player touching so it could be breaking on the :GetPlayerFromCharacter function so instead do
script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild('Humanoid') then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
local Tele = Player.Character:FindFirstChild("Tele")
if not Tele then return end
if not Tele.Value then
Tele.Value = true
Player.Character.HumanoidRootPart.CFrame = Respawner.CFrame + Vector3.new(0, 5, 0)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 85
wait(3)
Tele.Value = false
end
end
end)
local Respawner = workspace.respawner
local Players = game:GetService("Players")
script.Parent.Touched:Connect(function(hit)
local playerObject = Players:GetPlayerFromCharacter(hit.Parent)
if playerObject then
local character = playerObject.Character
local tele = character:FindFirstChild("Tele")
if not tele then return end
if not tele.Value then
tele.Value = true
character:PivotTo(Respawner.CFrame + Vector3.new(0, 5, 0))
playerObject.leaderstats.Coins.Value += 85
task.wait(3)
Tele.Value = false
end
end
end