So I’m writing a script that teleports you when you touch a part and have a certain amount of rebirths, but it doesn’t work, I’ve tried googling the problem and changed the code multiple times but nothing worked.
Code:
local Destination = game.Workspace.TPs.TP1
local function Check(leaderstats, HumanoidRootPart)
local Rebirths = leaderstats:FindFirstChild("Rebirths")
if Rebirths.Value >= 1000000 then
HumanoidRootPart.CFrame = Destination.CFrame
print("Teleported")
end
end
script.Parent.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if not Humanoid then
-- ignore
elseif Humanoid then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
print(Player)
local leaderstats = Player:FindFirstChild("leaderstats")
if leaderstats then
print("Leaderstats found")
Check(leaderstats,hit.Parent:FindFirstChild("HumanoidRootPart"))
end
end
end)
I have replicated the thing you want to do there and it worked perfectly fine for me.
So what could be wrong is something inside your leaderstats setup script for example something got a typo or the leaderstats folder did not get parented to the player?
make sure you’re setting the rebirths on serverside
setting it in studio using the properties window is clientside unless you manually click the button in the test tab to swap to serverside