local redpart = script.Parent local Player = game.Players.LocalPlayer local character = Player:GetPlayerFromCharacter(character) local humanoid = character:FindFirstChild("Humanoid") redpart.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then while humanoid.Health > 0 do wait(0.2) humanoid:TakeDamage(10) end end end)
Ive tried doing this in global and local scripts but Player.Character kept erroring for me on global so just did local (my script isnt working on either though)
Hello Bloxerventure!
You can only define player in local scripts and define if a part touched something in scripts. Here is a script that you should instead use in a global script
local redpart = script.Parent redpart.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then while hit.Parent.Humanoid.Health > 0 do wait(0.2) hit.Parent.Humanoid:TakeDamage(10) end end end)
I don't understand why you need to do Player.Character or the other variables for a Touched event to damage someone but you can simply do this.
local redpart = script.Parent redpart.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local humanoid = hit.Parent.Humanoid while humanoid.Health > 0 do wait(0.2) humanoid:TakeDamage(10) end end end)