Why .Touch Event only runs after jumping on it?
Hello, I want to script so if you touched a part five times, you'll get teleported back to the spawn point. It works fine, managed to fix how to update a gui and it wont loop while you stand on it, but it wont run everytime. There's no error given in output section. I've also looked for some solutions via Google, but no success. Here's the code:
02 | local blacklisted = false |
04 | local playerService = game:GetService( "Players" ) |
05 | local player = playerService.LocalPlayer |
07 | local gui = player:WaitForChild( "PlayerGui" ):WaitForChild( "ScreenGui" ).HitDamagePartCount |
09 | local valueText = gui.CountTextValue |
10 | local valueInt = gui.CountValue |
12 | local count = gui.Count |
14 | local teleporter = workspace.Teleport |
15 | local touch = workspace.Touch |
18 | function DamageGuiChanger(hit) |
19 | if blacklisted = = false then |
20 | local humRoot = hit.Parent:FindFirstChild( "HumanoidRootPart" ) |
21 | if hit = = humRoot then |
22 | if valueInt.Value < 4 then |
23 | valueInt.Value = valueInt.Value + 1 |
26 | humRoot.CFrame = CFrame.new(teleporter.Position.X, teleporter.Position.Y + 2 , teleporter.Position.Z) |
30 | if valueInt.Value = = 0 then |
31 | count.TextColor 3 = Color 3. new( 0 , 0.666667 , 0 ) |
32 | elseif valueInt.Value = = 1 then |
33 | count.TextColor 3 = Color 3. new( 0.333333 , 0.666667 , 0 ) |
34 | elseif valueInt.Value = = 2 then |
35 | count.TextColor 3 = Color 3. new( 0.666667 , 0.666667 , 0 ) |
36 | elseif valueInt.Value = = 3 then |
37 | count.TextColor 3 = Color 3. new( 1 , 1 , 0 ) |
38 | elseif valueInt.Value = = 4 then |
39 | count.TextColor 3 = Color 3. new( 1 , 0.666667 , 0 ) |
41 | count.TextColor 3 = Color 3. new( 1 , 0 , 0 ) |
52 | valueText.Value = "5 of " .. tostring (valueInt.Value).. " hits to get teleported back!" |
53 | count.Text = valueText.Value |
54 | touch.Touched:Connect(DamageGuiChanger) |
You may look between line 19 and 46. Hopefully somebody can help me. G'Day.