Yes, a RemoteEvent. Sure.
1 | local detector = script.Parent.Detector -- The click detector. |
2 | detector.MouseClick:connect( function (plr) |
3 | plr.PlayerScripts.IntValue.Value = plr.PlayerScripts.IntValue.Value - 1 -- Basically I need to change values. |
4 |
5 | end ) |
Okay so look this is hard to explain.
But I can't use a RemoteEvent with the click detector local, and then telling the server who clicked it. Why? I need to clone the script and put it in bricks. If the same script that is waiting for this code
1 | Event.OnServerEvent:connect( function () |
then let's say there's 25 parts with the same script in it, the scripts would all then get fired, right?
So I need a way around the server calling all 25 scripts to do the action. I have tried this, and it is what happened.
So
I am wondering, what would I do? I have tried custom coding the whole click detector using Mouse.Target and such. I am extremely lost, if you need more examples message me.
Yea, I just started learning FE and it is confusing at first, but you'll get it with practice.
So, with FE enabled, the game is practically in two (or how I view it), the server (What everyone else sees) and the client (What the player sees). In your case, you're wanting the player to click a brick or click one of the bricks in a group of bricks to do something.
So if this was one brick, you would do:
1 | -- Client Side, could be placed in StarterPlayerScripts |
2 | game.Workspace.ClickThis.ClickDetector.MouseButton 1 Click:connect( function () -- event |
3 | game.ReplicatedStorage.Event:FireServer() -- Client to Server, so you FireServer()(Event=RemoteE) |
4 | end ) |
1 | -- Server Side, could be placed inside your ClickDetector or ServerScriptService |
2 | game.ReplicatedStorage.Event.OnServerEvent:connect( function () -- So when Event is fired/called |
3 | -- Stuff you want done. Remeber, this will change stuff on the server-side not locally |
4 | end ) |
Multiple Bricks would be the same exact thing, but you'd create a table with 'in pairs' and the bricks need to be in a model:
1 | for i,v in pairs (game.Workspace.Model:GetChildren()) do -- gets all the children of the model |
2 | v.ClickDetector.MouseButton 1 Click:connect( function () -- each brick has a clickDetector |
3 | game.ReplicatedStorage.Event:FireServer() |
4 | end ) |
5 | end |