Hi! I’m currently messing around in a game that I’m making, I’m trying to make it so if you click one of the many parts, it loses health. Once it loses all of its health, it is destroyed, and a leaderstat point is awarded.
Currently I have it so it gets the player’s mouse, then if the player holds down, it checks if the selected part can be destroyed. If it can, it continues, if not it stops. Then it checks if the blocks health it above 0, if so it will lose one health point every 0.3 seconds.
My current problem is that I currently have the script in a local script (things will only effect the client, which is one problem with my current script), and when I try to move it into a server sided script, it just doesn’t work at all since you can’t get the player’s mouse in a server script.
Although some of the checks are working, even now while it partially works it won’t change the blocks int value health.
This is my current script. (its in a local script in starter character scripts)
mouse.Button1Down:Connect(function(Player)
if mouse.Target.CanDestroy == true then
local target = mouse.Target
if target.Health.Value > 0 then
target.Health.Value = target.Health.Value - 1
wait(0.3)
end
end
end)```
Please let me know on what I should change, thanks!
You can do so with a remote event, though I suggest creating a server script that runs through all of the available blocks and adds a click detector to each and every one. Then, you could make a script that handles when the player clicks the via the ClickDetector.MouseClick() function.
I wouldn’t suggest using click detectors for this as it can get really messy. For example, what if you want to add a feature where the player must hold down their mouse to take health from the block.