Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Call a function in a script without stopping script?

Okay so in this script, I need it to call a function but then continue on with the script without waiting for the function to finish. What can I do?

its calling the fixPlayer function and I need it to not wait for that function to finish to continue killing other players/blowing them up

sp=script.Parent.Parent:WaitForChild("HitBox")
local numX = 1
local numY = 1
local numZ = 1

function fixPlayer()
	for i, v in pairs(game.Players:GetChildren()) do
		if v:FindFirstChild(v.Name.."Dead") then
			v:WaitForChild(v.Name.."Dead"):Destroy()
			local t = v.Character:WaitForChild("Torso")
			local h = v.Character:WaitForChild("Humanoid")
			for Jump=25,1,-1 do
				wait()
				t.CFrame = t.CFrame + Vector3.new(0,7.5,0)
			end
			t.Anchored = false
			t.CFrame = script.Parent.Parent.Parent.Parent.SecondPosition.CFrame
			local spawns = script.Parent.Parent.Parent.Parent.Spawns:GetChildren()
			v.Character:MoveTo(spawns[math.random(1,4)].Position)
			h.WalkSpeed = 16
			game.Players[t.Parent.Name].PlayerValues.ObjectPickedUp.Value = false
		end
	end
end

repeat wait()
	wait()
	if script.Parent ~= nil then
		for _, v in pairs(game.Players:GetChildren()) do
			if v then
				local h=v.Character:FindFirstChild("Humanoid")
				local t=v.Character:FindFirstChild("Torso")
				if t and h and h.Health>0 then
					local relative=sp.CFrame:toObjectSpace(t.CFrame).p
					if relative.x<sp.Size.x*numX and relative.x>-sp.Size.x*numX and relative.y<sp.Size.y*numY and relative.y>-sp.Size.y*numY and relative.z<sp.Size.z*numZ and relative.z>-sp.Size.z*numZ and script.Parent ~= nil then
						if script.Parent.Exploder.Value == true then
							script.Disabled = true
							h.WalkSpeed = 0
							script.PlayerScream:Play()
							t.Anchored = true
							local tag = script.KillTag:Clone()
							tag.Parent = game.Players[t.Parent.Name]
							tag.Name = ""..t.Parent.Name.."Dead"
							fixPlayer()
						end
					end
				end
			end
		end
	end
until script.Disabled == true or script.Parent == nil

1 answer

✓ Accepted answer

To my knowledge, the script always reads through the code; but it's near instantaneous anyway, so you should be able to run a standard function and the effects would still be the same.

1 comment

0

found that you can do spawn(function() --Wrtie stuffs end) and it works that way

This discussion is preserved as it was. New answers, comments, and votes are closed.