This teleport script that work normally in studio, but doesn't work at all in a server. Can someone fix this for me ?
01 | local mapIns = "map" .. script.Parent.Parent.mapID.Value |
02 | local spawnL = workspace [ mapIns ] .spawn |
03 | local hitRequired = script.Parent.Parent.hitReq.Value |
04 |
05 | script.Parent.Touched:connect( function (hit) |
06 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
07 | local notice = player.PlayerGui.notice.text |
08 | local playerstats = player.leaderstats |
09 | if hit and hit.Parent and hit.Parent:FindFirstChild( "Humanoid" ) and playerstats.Hits.Value > = hitRequired then |
10 | hit.Parent.HumanoidRootPart.CFrame = CFrame.new(spawnL.Position) |
11 | elseif playerstats.Hits.Value < hitRequired then |
12 | notice.Text = "You need " .. hitRequired .. " hits or more to enter this!" |
13 | notice.Visible = true |
14 | wait( 3.5 ) |
15 | notice.Visible = false |
16 | end |
17 | end ) |
The server doesn't have access to the PlayerGui, but luckily the client has access to the Character. You need to do this from the client:
LocalScript in StarterPack or PlayerGui
01 | local plr = game.Players.LocalPlayer --You |
02 | local SomeBrick --The brick to touch |
03 | local mapIns = "map" .. SomeBrick.Parent.mapID.Value |
04 | local spawnL = workspace [ mapIns ] .spawn |
05 | local hitRequired = SomeBrick.Parent.hitReq.Value |
06 | local notice = plr:WaitForChild( "PlayerGui" ):WaitForChild( "notice" ):WaitForChild( "text" ) |
07 | local playerstats = plr:WaitForChild( "leaderstats" ) |
08 |
09 | SomeBrick.Touched:Connect( function (hit) |
10 | --Get player that touched |
11 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
12 | --If it's you, and you have prerequisites |
13 | if player = = plr and playerstats.Hits.Value > = hitRequired then |
14 | --Teleport |
15 | local root = hit.Parent.HumanoidRootPart |