Boulders breaking for everyone

Hello! I’m having an issue where my local script happens for all the clients. I want it so it only breaks the boulders on your screen. But for some reason when I did a Local server test the boulders broke for all of the players. Please let me know if I’m doing something wrong! Also, this is in Starter Gui

local boulderHitBox = game.Workspace.SpawnPlace.BouldersHitBox
local boulder = game.Workspace.SpawnPlace.Bolders
local boulderChildren = boulder:GetChildren()
local rockBreakingSound = game.Workspace.SpawnPlace.RocksBreaking
local swordErrorText = script.Parent.SwordErrorText

boulderHitBox.Touched:Connect(function(sword)
	if sword.Parent.Name == "FirstSword" then
		boulderHitBox:Destroy()
		for i,v in pairs(boulderChildren) do
			v:Destroy()
		end
		rockBreakingSound.Playing = true
	else
		swordErrorText.Visible = true
	end
end)

boulderHitBox.TouchEnded:Connect(function()
	swordErrorText.Visible = false
end)

What is the error? can you show me them?

Just try this

boulderHitBox.Touched:Connect(function(sword)
	if sword.Parent.Name == "FirstSword" then
		boulderHitBox:Destroy()
		for i,v in pairs(boulder:GetChildren()) do
			v:Destroy()
		end
		rockBreakingSound.Playing = true
	else
		swordErrorText.Visible = true
	end
end)

boulderHitBox.TouchEnded:Connect(function()
	swordErrorText.Visible = false
end)

I tried getting a var for children before it didnt work

Is the spelling right for the second line where it says “Bolders”?

There isn’t an error. The only thing that’s happening is that the boulders are breaking for all of the clients but I only want the boulders to break for the person who broke them

Is this script on the server? It will appear for everyone if it is.

1 Like

It’s a LocalScript inside of StarterGui

So I see why. Your detecting when the boulder is touched it destroys! But every client is gonna get this message when the part is touched. Every client is getting it because your not detecting when the part is touched.

1 Like

Correction, the Touched event is being fired when 1 person touches it.

	if sword.Parent.Name == "FirstSword" then
         if sword.Parent.Parent:FindFirstChild("Humanoid") then -- add/remove parents until it points to the player's Character
              if game.Players.LocalPlayer.Name ==  sword.Parent.Parent.Name then
		boulderHitBox:Destroy()
		for i,v in pairs(boulder:GetChildren()) do
			v:Destroy()
		end
		rockBreakingSound.Playing = true
	else
		swordErrorText.Visible = true
	end
end
end
end)

boulderHitBox.TouchEnded:Connect(function()
	swordErrorText.Visible = false
end) ```
2 Likes

Yes, now you need to check if the player who touched it is the local player. Right now, it will detect when the boulder is touched. If ANYONE or ANYTHING touches it, it will delete.

1 Like

Thank you so much :smile:!!! I’m glad it works now!