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:
-- VARIABLES --
local blacklisted = false
local playerService = game:GetService("Players")
local player = playerService.LocalPlayer
local gui = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").HitDamagePartCount
local valueText = gui.CountTextValue
local valueInt = gui.CountValue
local count = gui.Count
local teleporter = workspace.Teleport
local touch = workspace.Touch
-- FUNCTION --
function DamageGuiChanger(hit)
if blacklisted == false then
local humRoot = hit.Parent:FindFirstChild("HumanoidRootPart")
if hit == humRoot then
if valueInt.Value < 4 then
valueInt.Value = valueInt.Value + 1
print(hit)
else
humRoot.CFrame = CFrame.new(teleporter.Position.X, teleporter.Position.Y + 2, teleporter.Position.Z)
wait()
valueInt.Value = 0
end
if valueInt.Value == 0 then
count.TextColor3 = Color3.new(0, 0.666667, 0)
elseif valueInt.Value == 1 then
count.TextColor3 = Color3.new(0.333333, 0.666667, 0)
elseif valueInt.Value == 2 then
count.TextColor3 = Color3.new(0.666667, 0.666667, 0)
elseif valueInt.Value == 3 then
count.TextColor3 = Color3.new(1, 1, 0)
elseif valueInt.Value == 4 then
count.TextColor3 = Color3.new(1, 0.666667, 0)
else
count.TextColor3 = Color3.new(1, 0, 0)
end
end
blacklisted = true
wait(.5)
blacklisted = false
end
end
-- MAIN --
while wait() do
valueText.Value = "5 of "..tostring(valueInt.Value).." hits to get teleported back!"
count.Text = valueText.Value
touch.Touched:Connect(DamageGuiChanger)
end
You may look between line 19 and 46. Hopefully somebody can help me. G'Day.

1 comment
Thanks, I'll look if it works. If it does, I'll accept ur answer.