Hello, basically, I want to be able to create a part which follows the user continuously through a repeat loop, and then I want to destroy it.
I was doing fine until I ran into an issue, basically, my repeat loop is saying that ‘Activated’ is true, even though in reality, it’s false. I tested with printing. Why is this the case, and how can I make my repeat until stop loop when I fire the second remote event into the server?
I’ve looked for solutions, but nothing on the Devforum seems to be working for me
LOCAL SCRIPT
local UserInputService = game:GetService("UserInputService")
local HpEn = game.ReplicatedStorage.HpEn
local Player = game.Players.LocalPlayer
local Activated = false
UserInputService.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.F and Activated == false then
Activated = true
HpEn:FireServer(Activated)
print ("En has been activated . .")
elseif input.KeyCode == Enum.KeyCode.F and Activated == true then
Activated = false
HpEn:FireServer(Activated)
print ("En has been deactivated . .")
end
end)
HpEn.OnClientEvent:Connect(function()
print ("RETURNED TO THE CLIENT!")
end)
SERVER SCRIPT
local HpEn = game.ReplicatedStorage.HpEn
HpEn.OnServerEvent:Connect(function(Player, Activated)
local Char = Player.Character
print ("Server has been reached!")
print (Activated)
if Activated == true then
local Newpart = Instance.new("Part")
Newpart.Name = "What's Goodie?"
Newpart.Shape = "Ball"
Newpart.Transparency = 0.9
Newpart.CanCollide = false
Newpart.Anchored = true
Newpart.Parent = game.Workspace
Newpart.Position = Vector3.new(0,10,0)
Newpart.Size = Vector3.new(20,20,20)
Newpart.Material = "Neon"
repeat
wait (0.001)
Newpart.CFrame = Char.LowerTorso.CFrame
print (Activated)
until Activated == false
else if Activated == false then
print ("PART HAS BEEN DESTROYED BRUH!")
end
end
end)