Now, this is probably another dumb question i made but how can i make it work correctly? I made it print("hi") incase before i posted this, but failed to print..
local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.Button1Down:Connect(function() if mouse.Target.Parent == "Test" then --Probably can be a table ~intepcs local Test = workspace.Folder.Test Test.Humanoid.Health = 25 end end)
The reason for this is line 6.
if mouse.Target.Parent == "Test" then
The Mouse.Target
property holds a reference, a reference to the BasePart
the mouse is hovering over. In order to fix this, you should check the Name
of the Target
.
local UserInputService = game:GetService("UserInputService") local Mouse = game:GetService("Players").LocalPlayer:GetMouse() UserInputService.InputBegan:Connect(function(input, gpe) if input.UserInputType == Enum.UserInputType.MouseButton1 then -- If they clicked the button... if not Mouse.Target then return end -- If they are pointing to the sky, Target is nil. if Mouse.Target.Parent.Name == "Test" then -- Checks the name. Mouse.Target.Parent.Humanoid.Health = 25 end end end)
And finally, remember to indent your code properly. Your end
on line 9 is not inside of the event, it is shifted to the left. Even if it's one line, it is important to have indented code, for the sake of readability.