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

My winners teleporter script doesn't work?!

Hello guys, I make question yesterday and MCAndRobloxUnited answered me. I tried the script by MCAndRobloxUnited At first it did not work but when I added "end" in line 10 it works with me, but when I published the game it doesn't work, It is only work in ROBLOX Studio. Please help me guys. this is the script I used by MCAndRobloxUnited:

function onTouched(hit) 
  print("Teleport")
  local human = hit.Parent:FindFirstChild("HumanoidRootPart")
  local brick = script.Parent
  if game.Players.LocalPlayer.leaderstats.Stages.Value == 100 then
  if (human ~= nil) then
   human.CFrame= CFrame.new(Vector3.new(Position))
   end
end
end

script.Parent.Touched:Connect(onTouched)

1 answer

✓ Accepted answer

You won't be able to use localplayer in a server script, so just make a small adjustment:

local players = game.Players
local brick = script.Parent

function onTouched(hit) 
  print("Teleport")
  local human = hit.Parent:FindFirstChild("HumanoidRootPart")
  local player = players:GetPlayerFromCharacter(hit.Parent)
  if human and player then
     if player.leaderstats.Stages.Value == 100 then
         human.CFrame= CFrame.new(Vector3.new(Position))
     end
  end
end

script.Parent.Touched:Connect(onTouched)

3 comments

1

You are awesome thanks a lot <3

1

you should have done local players = game:GetService("Players")

0

the service will load before the script does, doesn't matter

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