How do make all the players not teleport but you

so i made a script that when you touch the TeleportBrick you get teleported, but every time i did that every player in the server gets teleported too, can you guys fix my code?

local Detect = game.Workspace.TeleportBrick


Detect.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.Screen.Autozoom.Disabled = true
		script.Parent.Screen.ResetOnSpawn = false
		script.Parent.Screen.UnEquipScript.Disabled = false
		script.Parent.Screen.ButtonFrame.Play.ingame["ingame"].Disabled = true
		script.Parent.VotingGui.JumpEvent:FireServer()
		script.Parent.EmoteGui.OpenGui.Disabled = true
		script.Parent.EmoteGui.ToggleButton.Visible = false
		script.Parent.Screen.Enabled = true
		script.Parent.Screen.Camera1.Disabled = false
		script.Parent.HealthBarGui.Frame.Visible = false
		script.Parent.MobileDashGui.Enabled = false
		coreCall('SetCore', 'ResetButtonCallback', false)
		game.Workspace.Teleport2.RemoteFunction2:InvokeServer()
		game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid"):UnequipTools()
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
		workspace.Camera.CameraType = Enum.CameraType.Custom
	end
end)

note that ignore the rest of the rest of the code

This is a problem with using .Touched event on the client as I see .LocalPlayer in there.

See this community tutorial well explaining the issue and a solution on how to solve it.

1 Like

oh cool thank You For It!!!

local StarterGui = game:GetService("StarterGui")

local Gui = script.Parent
local Screen = Gui.Screen
local Camera = workspace.CurrentCamera
local Detect = workspace.TeleportBrick
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

Detect.Touched:Connect(function(Hit)
	local HitModel = Hit:FindFirstAncestorWhichIsA("Model")
	if HitModel then
		if HitModel == Character then
			Screen.Autozoom.Disabled = true
			Screen.ResetOnSpawn = false
			Screen.UnEquipScript.Disabled = false
			Screen.ButtonFrame.Play.ingame["ingame"].Disabled = true
			Gui.VotingGui.JumpEvent:FireServer()
			Gui.EmoteGui.OpenGui.Disabled = true
			Gui.EmoteGui.ToggleButton.Visible = false
			Screen.Enabled = true
			Screen.Camera1.Disabled = false
			Gui.HealthBarGui.Frame.Visible = false
			Gui.MobileDashGui.Enabled = false
			coreCall('SetCore', 'ResetButtonCallback', false)
			workspace.Teleport2.RemoteFunction2:InvokeServer()
			Humanoid:UnequipTools()
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
			Camera.CameraType = Enum.CameraType.Custom
		end
	end
end)

This is because you’re checking if the “something” which triggered the “Touched” event to fire on the BasePart instance has a “Humanoid” instance inside of it.

Instead you need to check if the “something” which triggered the “Touched” event to fire is the local player’s character for which the client-side script is running for.

1 Like