Local gui script is running for all players on server

I was running a dialogue scene and camera change on a server script that activated when a player touched a part. I changed it to a local script within the StarterGui and it still runs for every player on the server. I don’t understand why… I’ve double and triple checked to make sure the server version has been deleted. Any help is greatly appreciated!

local part = game.Workspace:WaitForChild("Clip1"):WaitForChild("Clip")
local debounce = false
local camera = game.Workspace.Camera
local cam = game.Workspace.CamPart1
local TweenService = game:GetService("TweenService")
local monFocus = game.Workspace:WaitForChild("BigMon1")
local clickforward = script.Parent.Parent:WaitForChild("Next")

clickforward.Visible = false


local function typewrite(textlabel, text)
	for i = 1, #text do
		textlabel.Text = string.sub(text, 1, i)
		wait(.01)
	end
end




local function playerStory(part) 
	
	
		
		local player = Players:GetPlayerFromCharacter(part.Parent)
		if not player then 
			local player = Players:GetPlayerFromCharacter(part.Parent.Parent)
			
			if not player then return end
		--print(player.Name .. " pressed me!")
			if player.Progress.Value >= 1 then return end
			player.Progress.Value = 1
		local humanoid = player.Character.Humanoid
			if humanoid ~= nil then humanoid.WalkSpeed = 0 end
			 debounce = true
			
			
	
			camera.CameraType = Enum.CameraType.Scriptable
			camera.CFrame = cam.CFrame
			
			
			
			wait(1.25)
		
			
			player.PlayerGui.Dialogue.Frame.Visible = true
			player.PlayerGui.Dialogue.Frame.Dialogue10.Visible = true
			
			
			
			typewrite(script.Parent, "I'm not sure who you are, but you don't look like you're supposed to be here.  Please leave...")
			clickforward.Visible = true
				clickforward.MouseButton1Click:wait()  

		
			humanoid.WalkSpeed = 16
			
			
			camera.CameraType = Enum.CameraType.Custom
	
		
		end 	
end

part.Touched:connect(playerStory)

part.Touched will run for everything including every player no matter if it is a local script so you need to check that the player that touched it is the local player for example:

if player == game.Players.LocalPlayer then
    -- Run the camera code
end
2 Likes

Thank you so much! I had no idea, that makes me think there’s some older codes I need to revisit in other games. I think every player is going to teleport when a single player does. :laughing:

Quick question but does the same issue happen with part.Touched on a server sided script?

Yeah part.Touched detects every single base part that touches it on server side or local side.

You can read about base parts here: BasePart | Roblox Creator Documentation

Thanks there’s a lot of great information there. It’s funny how I haven’t read over such a simple topic but there was still much to learn.

I was wondering if .touched was used to fire a remote event to the client of player, if it would fire for all players. I was trying to imagine the easiest way to compare the player to the touched part parent player if game.Players.LocalPlayer was not available (if it is a server sided script.)

Hi sorry I didn’t see your message.

well if you were using it to fire a client then you could do something like:

part.Touched:Connect(function(object)
  if object.Parent:FindFirstChildWhichIsA("Humanoid") and object.Name == "HumanoidRootPart" then
    remoteEvent:FireClient(game.Players:GetPlayerFromCharacter(object.Parent))
  end
end)

Here we can use the GetPlayerFromCharacter function: Players | Roblox Creator Documentation

1 Like