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

Script for teleporter not working as i want it to?

Asked by 5 years ago

``` local currentlevelvalue = game.Players.LocalPlayer.leaderstats.Level.Value local pad = script.Parent local teleportTo = workspace.level:FindFirstChild(currentlevelvalue)

pad.Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then local humanoidRoot = hit.Parent:FindFirstChild("HumanoidRootPart") if humanoidRoot then humanoidRoot.CFrame = teleportTo.CFrame end end end) ```

I want to create a block that on contact teleports you to a certain brick depending on your leaderboard score for example if your Level leaderboard value was 3 you would get sent to the brick called Level3. I'm not sure how to do this. I'm fairly new to lua but this is what i have. Could someone help me fix this code so it can perform the task i want?

0
Same Problem with a Player RedstonecraftHD 25 — 5y

1 answer

Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
5 years ago
Edited 5 years ago

It appears your script is local. It wont work. You need to change your Localscript to script. However it still won't work. That is because you no longer can use LocalPlayer property. You need to make adjustments.

local pad = script.Parent
local Players = game:GetService("Players")

pad.Touched:connect(function(hit)
 local humanoid = hit.Parent:FindFirstChild("Humanoid")
 if humanoid then
  local humanoidRoot = hit.Parent:FindFirstChild("HumanoidRootPart")
  if humanoidRoot then
   local player = Players:GetPlayerFromCharacter(hit.Parent)
   local currentlevelvalue = player.leaderstats.Level.Value
   local teleportTo = workspace.level:FindFirstChild(currentlevelvalue)
   humanoidRoot.CFrame =  teleportTo.CFrame
  end
 end
end)
Ad

Answer this question