Hey guys, I was wondering how I would be able to script a GUI button to damage the selected part. Example: You click a part, and the part you just selected will become the target. Using a button that appears at the bottom of the screen, you do damage to the part. depending on the tool you have the more damage it does.
Can someone please at least try and help me understand a simple and efficient way to do this? Thanks!
If the user is not targeting a part, that will return nil
Then tie it to UserInputService like:
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not gameProcessed then
local target = game:GetService("Players").LocalPlayer:GetMouse().Hit
if target then
-- do something, namely create a gui and store the target so that whenever a button is pressed it does something
end
end
end)