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

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

Asked by
Prioxis 673 Moderation Voter
10 years ago

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

Log in to vote
-1
Answered by
Tynezz 0
10 years ago
while not player.Character do wait() end
Ad
Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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
0
this works until the character dies then the entire thing errors out Prioxis 673 — 10y
0
No it does not. This PREVENTS the script from breaking if the character is not loaded yet. Perci1 4988 — 10y
Log in to vote
-3
Answered by 10 years ago

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

0
it doesn't really help what they said helped Prioxis 673 — 10y
0
sorry iamnoamesa 674 — 10y

Answer this question