Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

When touch, if the value in stats is 1, then will be teleported to another place, dont work, why?

im making a script that if the value of a stats is 1, then will be teleported to other place, but dont work, what i did wrong?

function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    local h = hit.Parent:findFirstChild("Humanoid")
    local thisplr = game.Players:findFirstChild(h.Parent.Name)
    local stats = thisplr:findFirstChild("stats")
    local cash = stats:findFirstChild("BornZone")
    if cash.Value == 1 then
        game:GetService("TeleportService"):Teleport(1225966253, player)
   end
end
script.Parent.Touched:connect(onTouched)


1 comment

0

Have if statement checking if its even a player touching, line 4 is unnessesary, FindFirstChild is capitalized. Try changing those three thingies

1 answer

✓ Accepted answer

Try doing this instead:

script.Parent.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and player:IsA("Player") then
local stats = player:WaitForChild'stats':FindFirstChild'BornZone'
if stats.Value == 1 then
game:GetService('TeleportService'):Teleport(1225966253, player)
end
end
end)

1 comment

0

just a side note, make sure that "BornZone" is an IntValue, and not a BoolValue. If it is a BoolValue, change to "if stats.Value == true then" instead.

This discussion is preserved as it was. New answers, comments, and votes are closed.