Only 1 zone is working at a time (its random each time)

Client Code:


local IsInZone = false

for i,v in pairs(workspace.Zones:GetChildren()) do
		
		local clonedWorldBoost = script.WorldBoost:Clone()
		
		clonedWorldBoost.Parent = v.Bubble
		clonedWorldBoost.TextLabel.Text = v.Name.." / x"..v.Boost.Value.."!".." ( req:"..v.ZoneReq.Value.."💪 )"
		clonedWorldBoost.Adornee = v.Bubble
	clonedWorldBoost.Enabled = true

		
end

local mag = nil

function UpdateZone(v, mag)
	
	
			if mag < 50 then
				if plr == game.Players.LocalPlayer and plr.IsInZone.Value == false then
			local result = game.ReplicatedStorage.ImportantEvents.UpdateZone:InvokeServer(v)
		         plr.IsInZone.Value = true
				end
	elseif mag > 50  and plr.IsInZone.Value == true then
		local result = game.ReplicatedStorage.ImportantEvents.UpdateZoneSecond:InvokeServer()
		plr.IsInZone.Value = false
			end
end
task.spawn(function()
	while task.wait(1) do
		for i,v in pairs(workspace.Zones:GetChildren()) do
				mag = (v.MagPart.Position -  char.PrimaryPart.Position).magnitude
				UpdateZone(v, mag)
	end
end
end)


Server code:


game.ReplicatedStorage.ImportantEvents.UpdateZone.OnServerInvoke = function(plr,zone)
	if game.Players:FindFirstChild(plr.Name).leaderstats.Muscle.Value >= zone.ZoneReq.Value  and game.Players:FindFirstChild(plr.Name).IsInZone.Value == false  then
		game.Players:FindFirstChild(plr.Name).StageBoost.Value *= zone.Boost.Value
		game.Players:FindFirstChild(plr.Name).IsInZone.Value = true
	end
end

game.ReplicatedStorage.ImportantEvents.UpdateZoneSecond.OnServerInvoke = function(plr)
	for i,v in pairs(StageModule) do
		if v.StageName == game.Players:FindFirstChild(plr.Name).leaderstats.Stage.Value and game.Players:FindFirstChild(plr.Name).IsInZone.Value == true then
			game.Players:FindFirstChild(plr.Name).StageBoost.Value = v.Buff
			game.Players:FindFirstChild(plr.Name).IsInZone.Value = false
		end
	end
end

Video:

2 Likes

When invoking remote functions, they yield until a value is returned.

local IsInZone = false

for i,v in pairs(workspace.Zones:GetChildren()) do

	local clonedWorldBoost = script.WorldBoost:Clone()
	
	clonedWorldBoost.Parent = v.Bubble
	clonedWorldBoost.TextLabel.Text = v.Name.." / x"..v.Boost.Value.."!".." ( req:"..v.ZoneReq.Value.."💪 )"
	clonedWorldBoost.Adornee = v.Bubble
clonedWorldBoost.Enabled = true

end

local mag = nil

function UpdateZone(v, mag)

		if mag < 50 then
			if plr == game.Players.LocalPlayer and plr.IsInZone.Value == false then
		local result = game.ReplicatedStorage.ImportantEvents.UpdateZone:InvokeServer(v)
	         plr.IsInZone.Value = true
			end
elseif mag > 50  and plr.IsInZone.Value == true then
	local result = game.ReplicatedStorage.ImportantEvents.UpdateZoneSecond:InvokeServer()
	plr.IsInZone.Value = false
		end

end
task.spawn(function()
while task.wait(1) do
for i,v in pairs(workspace.Zones:GetChildren()) do
mag = (v.MagPart.Position - char.PrimaryPart.Position).magnitude
UpdateZone(v, mag)
end
end
end)

in the client code, you invoke the functions “UpdateZone” and “UpdateZoneSecord” however the receiver ( in this case, the server) is not returning this so called “result”

1 Like

ohhh okay i see should i just use remote events then? or just remove the result thing

1 Like

You should use the remote events instead

it still only works for one of them

Would you mind showing me the updated code?

local mag = nil

function UpdateZone(v, mag)
	mag = (v.MagPart.Position -  char.PrimaryPart.Position).magnitude
	

	
	if mag < 50 then
		print(v.Name)
		print(v.Boost.Value)
		print(mag)
				if plr == game.Players.LocalPlayer and plr.IsInZone.Value == false then
			 game.ReplicatedStorage.ImportantEvents.UpdateZone:FireServer(v, v.Boost)
		         plr.IsInZone.Value = true
				end
	              elseif mag > 50  and plr.IsInZone.Value == true then
		         mag = nil
		       game.ReplicatedStorage.ImportantEvents.UpdateZoneReturn:FireServer()
		       plr.IsInZone.Value = false
	end
end
task.spawn(function()
	while task.wait(1) do
		for i,v in pairs(workspace.Zones:GetChildren()) do
				UpdateZone(v, mag)
	end
end
end)

server:

game.ReplicatedStorage.ImportantEvents.UpdateZone.OnServerEvent:Connect(function(plr,zone,boost)
	if plr.leaderstats.Muscle.Value >= zone.ZoneReq.Value  then
		plr.StageBoost.Value *= boost.Value
	end
end)

game.ReplicatedStorage.ImportantEvents.UpdateZoneReturn.OnServerEvent:Connect(function(plr)
	for i,v in pairs(StageModule) do
		if v.StageName == plr.leaderstats.Stage.Value  then
			plr.StageBoost.Value = v.Buff
		end
	end
end)

it still prints a seperate magnitude for each one and tells me the name on the zone im closest too so its being weird

Could u tell me if UpdateZoneReturn.OnServerEvent is fired when exiting the bubble?

yes it is sorry for the late reply

@Clousive its fixed thank you for your help

1 Like