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

How do I make an OnClicked function local?

Asked by 4 years ago

Hello, right now I am trying to make a wall that will turn CanCollide to False for the local player.

Right now the code is functional for a regular Script but not a Local Script.

I can give you my code anyways since it might be needed.

function onClicked()

game.Workspace.Wall1.CanCollide = false

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

Log in to vote
0
Answered by 4 years ago

To achieve this effect with a server script, you must use RemoteEvents and two scripts the script in the click block (server) should look like this:

function onClicked(plr)
print(plr.Name)
game.ReplicatedStorage.collision:FireClient(plr, workspace.Wall1)

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

A remote event should be placed in replicated storage ( i name it "collision" )

and the local script should be placed in startercharacterscripts, with the following code.

game.ReplicatedStorage.collision.OnClientEvent:Connect(function(part)
    part.CanCollide = false
end)

the local script can be sent for by any server script, to change the collision of any brick.

Hope this was helpful :)

Ad

Answer this question