I tried to make this barrier spawns near the player, however the value isn’t updating anytime
i searched through several threads and tried to put the value inside the loop, it still spawns the barrier on a fixed place
heres the code for the spawning
game.Players.PlayerAdded:Connect(function(player)
local enabled = false
game.ReplicatedStorage.ToggleBarrier.OnServerEvent:Connect(function()
if not enabled then
enabled = true
while wait(0.4) do
if enabled then
local offset = script.Offset
local Character = player.Character.HumanoidRootPart
local NewPart = game.ServerStorage.Barrier
local barrier = NewPart:Clone()
barrier.Position = Vector3.new(offset.Value, 16.5, -5998.6) + Vector3.new(math.floor(math.random(-2,2)*20),0,0)
barrier.Parent = workspace
game.Debris:AddItem(barrier, 5)
game.ReplicatedStorage.Barriermove:FireAllClients(player,barrier)
else
break
end
end
else
enabled = false
end
end)
end)
Changed the code, now it uses value inside script but still not changing where the barriers spawn
local offset = -62.175
game.Players.PlayerAdded:Connect(function(player)
local enabled = false
game.ReplicatedStorage.ToggleBarrier.OnServerEvent:Connect(function()
if not enabled then
enabled = true
while wait(0.4) do
if enabled then
local Character = player.Character.HumanoidRootPart
local NewPart = game.ServerStorage.Barrier
local barrier = NewPart:Clone()
barrier.Position = Vector3.new(offset, 16.5, -5998.6) + Vector3.new(math.floor(math.random(-2,2)*20),0,0)
barrier.Parent = workspace
game.Debris:AddItem(barrier, 5)
game.ReplicatedStorage.Barriermove:FireAllClients(player,barrier)
else
break
end
end
else
enabled = false
end
end)
end)
game.ReplicatedStorage.Add1.OnServerEvent:Connect(function()
offset += 20
print(offset)
end)
game.ReplicatedStorage.Negate1.OnServerEvent:Connect(function()
offset = 20
print(offset)
end)