Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

When tool part touches a brick, the brick should be unanchored. Help?

Hello, I'm working on something and I tried to fix this problem many times, I used RemoteEvents, and still nothing. Can someone help me please?

--local script script.Parent.Touched:Connect(function(hit) if hit.Name == "Breakable" then local currentbreak = hit.Name script.Parent.Parent.RemoteEvent:FireServer(currentbreak) else return end end)

and the server side script

script.Parent.RemoteEvent.OnServerEvent:Connect(function(currentbreak) currentbreak.Anchored = false end)

Note: There are multiple breakable bricks in the workspace, and the script should find a specific one, that was touched by the tool part. So I can't do something like this:

game.Workspace.Breakable.Anchored = false

Thanks!

2 comments

0

change it to currentbreak = hit

0

v Still nothing

1 answer

✓ Accepted answer

Hello.

Here are the errors you made:

  • You fired the object name instead of the object itself. So the server would do: object.Name.Anchored = false. Which makes no sense.
  • The first argument on "OnServerEvent" event will always be the player who fired the event.

Here is a fix:

Server Script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, object)
	if object.Name == "Breakable" then -- Checks should be made on the server since an exploiter could bypass the Client checks.
		object.Anchored = false -- UnAnchoring the object.
	end
end)

Tool LocalScript:

local DelayTime = 5
local Delay = false

script.Parent.Handle.Touched:Connect(function(object)
	if object.Name == "Breakable" and not Delay then -- Checks if the object name is "Breakable" and if Delay is false (Delay == false is the same as "not delay")
		Delay = true -- Makes Delay true
		game.ReplicatedStorage.RemoteEvent:FireServer(object) -- Fires the object to the server.
		wait(DelayTime) -- Wait the DelayTime (5 seconds)
		Delay = false -- After 5 seconds, the delay will become False.
	end
end)

1 comment

0

Thank you so much!!!!

This discussion is preserved as it was. New answers, comments, and votes are closed.