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

my teleport script where you need a certain amount of currency for it to work isn't working?

hi, i made a teleport script but i need to make sure that it only works if you have a certain amount of currency or more. the name of the currency is PowerBlocks

here is the script

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') then
        if hit.leaderboard.PowerBlocks.Value >= 2 then 
                hit.Parent.Head.CFrame = CFrame.new(-80, 15.5, 7)
        end
    end
end)

let me know if you find anything wrong with this script. thanks in advance from poopypigeon245

2 answers

✓ Accepted answer

The variable that you called hit is not the player instance but rather the body part of the character that touches the part. To get the player, you can use the :GetPlayerFromCharacter() function. As well as this, the leaderboard information should be stored inside something called leaderstats not leaderboard.

script.Parent.Touched:Connect(function(hit)
   if hit.Parent:FindFirstChild("Humanoid") then
      local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
      if plr and plr.leaderstats.PowerBlocks.Value >= 2 then
         hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-80,15.5,7)
      end
   end
end)

1 comment

0

thanks!

is there a leaderboard in your Humanoid?

If not, define player.

script.Parent.Touched:connect(function(hit)
player = game.Players:GetPlayerFromCharacter(hit.Parent)
character = hit.Parent
    if player and player:IsA("Player") then -- to check if it is a player and if the player exists
        if player.leaderboard.PowerBlocks.Value >= 2 then  -- i corrected, assuming that 'leaderboard' is in player
               character.Head.CFrame = CFrame.new(-80, 15.5, 7) -- not sure why are you only positioning the head
        end
    end
end)

1 comment

0

remove or add more ends, i didn't test the script. let me know if there's errors

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