Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

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)
0
thanks! poopypigeon245 22 — 6y
Ad
Log in to vote
0
Answered by
Astralyst 389 Moderation Voter
6 years ago
Edited 6 years ago

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)
0
remove or add more ends, i didn't test the script. let me know if there's errors Astralyst 389 — 6y

Answer this question