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

how do I make the script wait for the character to load?

I'm making a magic fighting game but my spells will load before the character does in online mode and then not work... and I've gotten help but it didn't help the issue

heres the script :

local Player = game:GetService'Players'.LocalPlayer
local character = Player:WaitForChild("Character")
local Mouse = Player:GetMouse()
local head = character:WaitForChild'Head'
local torso = character:WaitForChild'Torso'
local rightShoulder = Torso:WaitForChild'Right Shoulder'
Run = game:getService("RunService")




Mouse.KeyDown:connect(function(key)
	if script.Wait.Value == false then
if key == "f" then
	script.Wait.Value = true
	for i = 1, 2 do
			for i = 1, 12 do
				RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0.16)
				RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0)
				Run.Stepped:wait(0.01)
			end
			for i = 1, 12 do
				RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0)
				RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, -0.16)
				Run.Stepped:wait(0.005)
			end
		end
			for i = 1, 12 do
				RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0)
				RightShoulder.C0 = RightShoulder.C0 *CFrame.Angles(0, 0, 0)
				Run.Stepped:wait(0.005)
			end
game:getService("Chat"):Chat(Player.Character.Head, "FireBall!")
local p = Instance.new("Part", Workspace)
p.Color = Color3.new(0, 0, 0)
p.Transparency = 0.5
p.Size = Vector3.new(3, 3, 3)
p.TopSurface = "Smooth"
p.BottomSurface = "Smooth"
p.CanCollide = false
p.Shape = "Ball"
s = script.FD:Clone()
s.Parent = p
s.Disabled = false
p.CFrame = Player.Character.Torso.CFrame*CFrame.new(0, 0, -12)
y = Instance.new("BodyVelocity", p)
y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
y.velocity = Player.Character.Torso.CFrame.lookVector*80
local f = Instance.new("Fire", p)
wait(6)
game.Debris:addItem(p, 1)
script.Wait.Value = false
else print'waiting'
end
end
end)

3 answers

✓ Accepted answer
while not player.Character do wait() end

Character is a property, not a child, of a player. Therefore you cannot use WaitForChild() to wait for it, since it's not a child.

To wait for the character, use a repeat loop:

repeat wait() until Player.Character

Also you probably will need the parentheses for the GetService method.

game:GetService("Players").LocalPlayer

2 comments

0

this works until the character dies then the entire thing errors out

0

No it does not. This PREVENTS the script from breaking if the character is not loaded yet.

im not sure if thishelps but maybe make a anti-lagg script for charecter to load faster instead of making the scripts wait, sorry if this dosent answer you, im just guessing this might help, but i see its already answered so it dosent matter but you can add a anti lagg script

2 comments

0

it doesn't really help what they said helped

0

sorry

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