This is my script so far; it is set as the child of a hitbox:
01 | local debounce = false |
02 |
03 | script.Parent.Touched:connect( function (hit) |
04 | if debounce = = false then |
05 | print ( "1" ) |
06 | if not script.Parent.Name = = hit.Parent.Name then |
07 | print ( "2" ) |
08 | if hit and hit.Parent and hit.Parent:FindFirstChild( "Humanoid" ) then |
09 | print ( "3" ) |
10 | debounce = true |
11 | hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 10 |
12 | hit.Parent.Humanoid.WalkSpeed = 8 |
13 | wait( 1 ) |
14 | hit.Parent.Humanoid.WalkSpeed = 16 |
15 | debounce = false |
16 | end |
17 | end |
18 | end |
19 | end ) |
In line 6, I try to check if the script's parent's name is equal to the part it hit's name, but i think i did "hit.Parent.Name then" wrong. Any suggestions?
It looks like the checks are to make sure that it's a player you're touching. In that case, try this:
01 | local debounce = false |
02 |
03 | script.Parent.Touched:Connect( function (hit) |
04 | if not debounce then -- make sure debounce is set to false |
05 | debounce = true |
06 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
07 | if player then -- make sure we don't work with a nil value, so the next part can only be performed when it's a player we are touching |
08 | print (player.Name) -- This will print the player's name |
09 | local character = player.Character -- this is the player's avatar in Workspace |
10 |
11 | character.Humanoid.Health - = 10 -- take away 10 from health |
12 | character.Humanoid.WalkSpeed = 8 |
13 | wait( 1 ) |
14 | character.Humanoid.WalkSpeed = 16 |
15 |
16 | debounce = false |
17 | end |
18 | end |
19 | end ) |