0

# Why is my Touched event not working when the player touches the part?

So im trying to get the player, if he clicks a button(Text button) a part spawns, i got no problem with that, but when i try to make it so when the play touches the part they take damage, it doesnt work. Here is the following code

local btn = game.StarterGui.test2.test
end

script.Parent.MouseButton1Click:Connect(function()

local humanoid = game.Players.LocalPlayer:FindFirstChild("Humanoid")
local maxHP = humanoid.MaxHealth

humanoid.Health = maxHP - 0.70
script:Destroy()
end)
end)


0
Edited 4 days ago

Your function isn't returning anything. If you wanna get the touching part, you'll need to return something. Which is an instance.

local btn = game.Players.LocalPlayer:WaitForChild("PlayerGui").test2.test --Manipulate the PlayerGui, not StarterGui. Also you can use script.Parent if your local script is a descendant of ScreenGui.