Local button acting like server button

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    The button only to be shown to the player themselves/not be replicated to server.
  2. What is the issue? Include screenshots / videos if possible!
    Title/Replicated to server
    Here’s a video of it (Sorry, I have a low end PC with 2gb of ram so expect it to be laggy…)


3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
:confused:, I couldn’t find any…
It’s a local script that’s generated inside the player’s character when loaded…

Well it makes sense, both of the players have the local script inside their character so it will run for both of them. It’s not being replicated to the server, just both players have their own local script that changes the GUI.

I’m gettting confused, only one player (in this case, Player1) was pressing the button. The other player (Player2) did not.

Edit: How can I make it so that only the person who pressed the button can only see and interact the truss and can interact with the piece above it?

Oh I’m sorry I thought you meant the timer gui on the top, let me check again I understand now. Could I see your script so I can see what might be the issue?

If you’re confused what I meant, look at the video at 1:00 (That shows me, “Player1” pressing the button…)

Yeah I see it now, can I see your script?

Sorry that’s it’s long:

local function CloneToWorkspace()
	
	script.Parent.Parent:WaitForChild("The Maze (Eazy)").Button.Light.TouchInterest:Remove()
	local waitForChild = game.WaitForChild
	local modelclone = waitForChild(game:GetService("ReplicatedStorage"), "TrussModel")
	local model = modelclone:Clone()
	local Truss = Instance.new("TrussPart")
	local Maze = script.Parent.Parent:WaitForChild("The Maze (Eazy)")
	Maze.Button.Light.BrickColor = BrickColor.new(0,0,0)
	Truss.Anchored = true
	Truss.CanCollide = true
	Truss.BrickColor = BrickColor.new("Dark stone grey")
	Truss.Name = "Truss1"
	Truss.Position = Vector3.new(-71.56, 13.625, 1302.028)
	Truss.Size = Vector3.new(2, 24, 2)
	Truss.Parent = Maze
	model.Name = "Trusses"
	wait(3)
	Maze.TransparentPiece.CanCollide = true
	wait(7)
	model.Parent = Maze
end

connection = script.Parent.Parent:WaitForChild("The Maze (Eazy)").Button.Light.Touched:Connect(CloneToWorkspace)

Is this in a server script?____

Did you read the original post?

Though, the script wasn’t in the character in the beginning (wasn’t in StarterCharacterScripts). Instead, it was in server storage that would later be cloned into each player’s character when the map loaded (see code below):
Note: This is in a server script…

local children = game.Workspace:GetChildren()
for i,v in pairs(children) do
	if v:IsA("Model") then
		local clonescript = script.Parent.CloneScriptTheMazeEasy:Clone()		
		clonescript.Parent = v
		v.CloneScriptTheMazeEasy.Disabled = false
	end
end

Well the script that you just showed me a few posts back was a local script? This one:

local function CloneToWorkspace()
      --more code here ...
end

connection = script.Parent.Parent:WaitForChild("The Maze (Eazy)").Button.Light.Touched:Connect(CloneToWorkspace)

Yes. That was a local script. It just wasn’t natively in the player’s character in the beginning…

Your issue is that you’re trying to remove the touch interest to stop server touch events. Touch interests only handle sending of touch events, you’d have to delete it on the server and the client.

But, I really really would not recommend doing that as its very hacky and unnecessary. That’s really not a good way to filter touches. You’re also not checking what is actually touching the button part, so a random part that happens to be controlled by the client will also fire touches in that case.

You should be checking if the player that touched it is the local player instead, for example, like this:

local Players = game:GetService("Players")
local function CloneToWorkspace(object)
	-- Attempt to find a player for the part that touched the button
	local player
	repeat
		player = Players:GetPlayerFromCharacter(object)
		object = object.Parent
	until player or not object

	-- If no player touched the button, or the player isn't the local one, don't build the models
	if not player or player ~= Players.LocalPlayer then
		return
	end
	
	-- The rest of your callback code excluding the TouchInterest bit
end
-- Your event connection

That’s a lot more intuitive and a lot more reliable.

1 Like

Thank you. It worked. I fixed my code and now here it is when all of the stuff is added:

local Players = game:GetService("Players")
local function CloneToWorkspace(object)
	local player
	repeat
		player = Players:GetPlayerFromCharacter(object)
		object = object.Parent
	until player or not object
	if not player or player ~= Players.LocalPlayer then
		return
	end

	local waitForChild = game.WaitForChild
	local modelclone = waitForChild(game:GetService("ReplicatedStorage"), "TrussModel")
	local model = modelclone:Clone()
	local Truss = Instance.new("TrussPart")
	local Maze = script.Parent.Parent:WaitForChild("The Maze (Eazy)")
	Maze.Button.Light.BrickColor = BrickColor.new(0,0,0)
	Truss.Anchored = true
	Truss.CanCollide = true
	Truss.BrickColor = BrickColor.new("Dark stone grey")
	Truss.Name = "Truss1"
	Truss.Position = Vector3.new(-71.56, 13.625, 1302.028)
	Truss.Size = Vector3.new(2, 24, 2)
	Truss.Parent = Maze
	model.Name = "Trusses"
	wait(3)
	Maze.TransparentPiece.CanCollide = true
	wait(7)
	model.Parent = Maze
end

local connection = script.Parent.Parent:WaitForChild("The Maze (Eazy)").Button.Light.Touched:Connect(CloneToWorkspace)

And here is the video when completed: