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 5 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

--spawner Local script

local button = script.Parent --your textbutton
local remote = game.ReplicatedStorage:WaitForChild("Reemote")

button.MouseButton1Click:Connect(function()
    remote:FireServer()
end)

-

--weapon Local script

local button = script.Parent --your textbutton
local weaponRemote = game.ReplicatedStorage:WaitForChild("WeaponEvent")

button.MouseButton1Click:Connect(function()
    wait(5) --this is the problem
    weaponRemote:FireServer()
end)

-

--weaponscript
local famas = game.ReplicatedStorage.FAMAS
local scarL = game.ReplicatedStorage["SCAR-L"]
local famasClone = famas:Clone()
local scarLClone = scarL:Clone()
local remote = Instance.new("RemoteEvent")
remote.Parent = game.ReplicatedStorage
remote.Name = "WeaponEvent"

remote.OnServerEvent:Connect(function(plr)
    famasClone.Parent = plr.Backpack
    scarLClone.Parent = plr.Backpack
    print("weaponscript activated")
end)

-

--Spawnscript
math.randomseed(tick())
local remote = Instance.new("RemoteEvent")
remote.Parent = game.ReplicatedStorage
remote.Name = "Reemote"
local spawns = workspace.Spawns:GetChildren() -- a model of all the spawn bricks

remote.OnServerEvent:Connect(function(plr)
    plr:LoadCharacter()
    local PlayerSpawn = spawns[math.random(1,#spawns)]
    plr.Character:SetPrimaryPartCFrame(CFrame.new(PlayerSpawn.Position.X,PlayerSpawn.Position.Y + 5,PlayerSpawn.Position.Z))
    print("spawn script activated")
end)


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 — 5y
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 — 5y
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 — 5y
0
whats firing spawn script's remote? GoldAngelInDisguise 297 — 5y

Answer this question