Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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!

0
change it to currentbreak = hit Avi_i 2 — 5y
0
v Still nothing NathanielFawkes 9 — 5y

1 answer

Log in to vote
0
Answered by
JakyeRU 637 Moderation Voter
5 years ago

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)
0
Thank you so much!!!! NathanielFawkes 9 — 5y
Ad

Answer this question