So I am making an Undertale game and I was creating an ability/tool named “Teleport”.
I wanted to make a limit and if the player is too far, the cooldown is cleared and the game let player trying another teleportation.
I am using an Boolean Value who changes when its failing, and this one has a problem : it changes but does not block the “if/then” :
Local script :
local RS = game:GetService("ReplicatedStorage")
local cooldownvalue = 3
local teleportevent = RS:WaitForChild("TeleportEvent")
local tool = script.Parent
tool.RequiresHandle = false
function onActivation()
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local position = mouse.Hit
teleportevent:FireServer(position)
script.Enabled = false
wait(0.25)
if script.Parent.Failure.Value == true then
tool.Name = "Fail!"
wait(0.5)
tool.Name = "Teleport"
script.Enabled = true
else
cooldown()
script.Enabled = true
end
script.Parent.Failure.Value = false
end
tool.Activated:Connect(onActivation)
function cooldown()
tool.Name = "8"
wait(0.1)
tool.Name = "7.9"
wait(0.1)
tool.Name = "7.8"
wait(0.1)
tool.Name = "7.7"
wait(0.1)
tool.Name = "7.6"
wait(0.1)
tool.Name = "7.5"
wait(0.1)
tool.Name = "7.4"
wait(0.1)
tool.Name = "7.3"
wait(0.1)
tool.Name = "7.2"
wait(0.1)
tool.Name = "7.1"
wait(0.1)
tool.Name = "7"
wait(0.1)
tool.Name = "6.9"
wait(0.1)
tool.Name = "6.8"
wait(0.1)
tool.Name = "6.7"
wait(0.1)
tool.Name = "6.6"
wait(0.1)
tool.Name = "6.5"
wait(0.1)
tool.Name = "6.4"
wait(0.1)
tool.Name = "6.3"
wait(0.1)
tool.Name = "6.2"
wait(0.1)
tool.Name = "6.1"
wait(0.1)
tool.Name = "6"
wait(0.1)
tool.Name = "5.9"
wait(0.1)
tool.Name = "5.8"
wait(0.1)
tool.Name = "5.7"
wait(0.1)
tool.Name = "5.6"
wait(0.1)
tool.Name = "5.5"
wait(0.1)
tool.Name = "5.4"
wait(0.1)
tool.Name = "5.3"
wait(0.1)
tool.Name = "5.2"
wait(0.1)
tool.Name = "5.1"
wait(0.1)
tool.Name = "5"
wait(0.1)
tool.Name = "4.9"
wait(0.1)
tool.Name = "4.8"
wait(0.1)
tool.Name = "4.7"
wait(0.1)
tool.Name = "4.6"
wait(0.1)
tool.Name = "4.5"
wait(0.1)
tool.Name = "4.4"
wait(0.1)
tool.Name = "4.3"
wait(0.1)
tool.Name = "4.2"
wait(0.1)
tool.Name = "4.1"
wait(0.1)
tool.Name = "4"
wait(0.1)
tool.Name = "3.9"
wait(0.1)
tool.Name = "3.8"
wait(0.1)
tool.Name = "3.7"
wait(0.1)
tool.Name = "3.6"
wait(0.1)
tool.Name = "3.5"
wait(0.1)
tool.Name = "3.4"
wait(0.1)
tool.Name = "3.3"
wait(0.1)
tool.Name = "3.2"
wait(0.1)
tool.Name = "3.1"
wait(0.1)
tool.Name = "3"
wait(0.1)
tool.Name = "2.9"
wait(0.1)
tool.Name = "2.8"
wait(0.1)
tool.Name = "2.7"
wait(0.1)
tool.Name = "2.6"
wait(0.1)
tool.Name = "2.5"
wait(0.1)
tool.Name = "2.4"
wait(0.1)
tool.Name = "2.3"
wait(0.1)
tool.Name = "2.2"
wait(0.1)
tool.Name = "2.1"
wait(0.1)
tool.Name = "2"
wait(0.1)
tool.Name = "1.9"
wait(0.1)
tool.Name = "1.8"
wait(0.1)
tool.Name = "1.7"
wait(0.1)
tool.Name = "1.6"
wait(0.1)
tool.Name = "1.5"
wait(0.1)
tool.Name = "1.4"
wait(0.1)
tool.Name = "1.3"
wait(0.1)
tool.Name = "1.2"
wait(0.1)
tool.Name = "1.1"
wait(0.1)
tool.Name = "1.0"
wait(0.1)
tool.Name = "0.9"
wait(0.1)
tool.Name = "0.8"
wait(0.1)
tool.Name = "0.7"
wait(0.1)
tool.Name = "0.6"
wait(0.1)
tool.Name = "0.5"
wait(0.1)
tool.Name = "0.4"
wait(0.1)
tool.Name = "0.3"
wait(0.1)
tool.Name = "0.2"
wait(0.1)
tool.Name = "0.1"
wait(0.1)
tool.Name = "0"
wait(0.1)
tool.Name = "Teleport"
wait(0.1)
end
Server Script :
local RS = game:GetService("ReplicatedStorage")
local TeleportEvent = RS:WaitForChild("TeleportEvent")
TeleportEvent.OnServerEvent:Connect(function(player, position)
local character = player.Character
local primarypart = character.PrimaryPart
if (primarypart.Position - position.Position).Magnitude <= 50 then
print("good")
primarypart.CFrame = CFrame.new(position.X, position.Y + 2, position.Z)
else
print("fail")
script.Parent.Failure.Value = true
print("changed")
print(script.Parent.Failure.Value)
end
end)
And some screenshots of the “prints” :
(there is writen “true” for the last print but it is not blocking the local script at line 15)
Sorry if its bad, its my first post so i dont know really how to use it ^^
Thanks for everyone who will help me