This is the code i tried to use.
local player = game.Players.LocalPlayer local Players = game:GetService("Players") script.Parent.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) local Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid") if Players.LocalPlayer.Character.leaderstats.rebirths.Value <= 3 then if plr then plr.Character.HumanoidRootPart.CFrame = CFrame.new(1476.7, 0.5, -173.8) end end end)
Your question was vague but I hope this works!
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid") local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if hit.Parent.leaderstats.rebirths.Value <= 3 then if plr then plr.Character.HumanoidRootPart.CFrame = CFrame.new(1476.7, 0.5, -173.8) end end end end)
You got a few things wrong. One thing you need to remember is that Players:GetPlayerFromCharacter(char)
returns the player, and nil
if no player is found. You don't need to do anything else other than checking if its valid.
With this, we can detect if the receiving end of the .Touched signal is a player. Like so:
script.Parent.Touched:Connect(function(otherPart) -- Attempt to get the player local plr = game.Players:GetPlayerFromCharacter(otherPart.Parent) -- Check if the player actually exists before doing anything with it - `nil` is falsey if plr then -- Player exists. Now we can access the leaderstats! if plr.leaderstats.rebirths.Value <= 3 then -- Leaderstats are under or equal to 3, teleport to wherever you like plr.Character.HumanoidRootPart.CFrame = CFrame.new(...) end end)