This teleport script that work normally in studio, but doesn't work at all in a server. Can someone fix this for me ?
local mapIns = "map" .. script.Parent.Parent.mapID.Value local spawnL = workspace[mapIns].spawn local hitRequired = script.Parent.Parent.hitReq.Value script.Parent.Touched:connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) local notice = player.PlayerGui.notice.text local playerstats = player.leaderstats if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and playerstats.Hits.Value >= hitRequired then hit.Parent.HumanoidRootPart.CFrame = CFrame.new(spawnL.Position) elseif playerstats.Hits.Value < hitRequired then notice.Text = "You need " .. hitRequired .. " hits or more to enter this!" notice.Visible = true wait(3.5) notice.Visible = false end 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
local plr = game.Players.LocalPlayer --You local SomeBrick --The brick to touch local mapIns = "map" .. SomeBrick.Parent.mapID.Value local spawnL = workspace[mapIns].spawn local hitRequired = SomeBrick.Parent.hitReq.Value local notice = plr:WaitForChild("PlayerGui"):WaitForChild("notice"):WaitForChild("text") local playerstats = plr:WaitForChild("leaderstats") SomeBrick.Touched:Connect(function(hit) --Get player that touched local player = game.Players:GetPlayerFromCharacter(hit.Parent) --If it's you, and you have prerequisites if player == plr and playerstats.Hits.Value >= hitRequired then --Teleport local root = hit.Parent.HumanoidRootPart root.CFrame = CFrame.new(spawn.Position) else --Otherwise --Notify them notice.Text = "You need " .. hitRequired .. " hits or more to enter this!" notice.Visible = true wait(3.5) notice.Visible = false end end)