Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my wait function is not working properly?

Asked by 6 years ago

I tried to fire a remote event after 5 seconds but it didn't seem to work. I tried using print to debug it and still

these are all my script involving this problem

1--spawner Local script
2 
3local button = script.Parent --your textbutton
4local remote = game.ReplicatedStorage:WaitForChild("Reemote")
5 
6button.MouseButton1Click:Connect(function()
7    remote:FireServer()
8end)

-

1--weapon Local script
2 
3local button = script.Parent --your textbutton
4local weaponRemote = game.ReplicatedStorage:WaitForChild("WeaponEvent")
5 
6button.MouseButton1Click:Connect(function()
7    wait(5) --this is the problem
8    weaponRemote:FireServer()
9end)

-

01--weaponscript
02local famas = game.ReplicatedStorage.FAMAS
03local scarL = game.ReplicatedStorage["SCAR-L"]
04local famasClone = famas:Clone()
05local scarLClone = scarL:Clone()
06local remote = Instance.new("RemoteEvent")
07remote.Parent = game.ReplicatedStorage
08remote.Name = "WeaponEvent"
09 
10remote.OnServerEvent:Connect(function(plr)
11    famasClone.Parent = plr.Backpack
12    scarLClone.Parent = plr.Backpack
13    print("weaponscript activated")
14end)

-

01--Spawnscript
02math.randomseed(tick())
03local remote = Instance.new("RemoteEvent")
04remote.Parent = game.ReplicatedStorage
05remote.Name = "Reemote"
06local spawns = workspace.Spawns:GetChildren() -- a model of all the spawn bricks
07 
08remote.OnServerEvent:Connect(function(plr)
09    plr:LoadCharacter()
10    local PlayerSpawn = spawns[math.random(1,#spawns)]
11    plr.Character:SetPrimaryPartCFrame(CFrame.new(PlayerSpawn.Position.X,PlayerSpawn.Position.Y + 5,PlayerSpawn.Position.Z))
12    print("spawn script activated")
13end)

the output will be like this

weaponscript activated

spawn script activated

where the weapon script got activated first

0
So if im not wrong you want the spawn script to be activated first? starmaq 1290 — 6y
0
If that's the case, the one-way message between client and server or the other way around is not immediate, the network connection between the client and server will determine how quickly this happens. starmaq 1290 — 6y
0
i guess what u can do is, add a boolean value object parented to your serversided spawnscript and name it "Activated", it will be set to false at first, and do script.Spawned = true in your spawnscript at the end. got the idea? and in your weapons script add an if statment checking if Activated == true, now weapons script will never work until the spawnscript is activated first starmaq 1290 — 6y
0
whats firing spawn script's remote? GoldAngelInDisguise 297 — 6y

Answer this question