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

Whenever I go in-game to test my scripts, they don't work. Help?

Asked by 9 years ago

This script works, but is there anything preventing it from working in-game?

Player = game.Players.LocalPlayer
Character = Player.Character
Torso = Character.Torso
Mouse = Player:GetMouse()
RS = Character.Torso["Right Shoulder"]
LS = Character.Torso["Left Shoulder"]
hold = false
f = script.Parent

Mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "v" then
        RS.C0 = RS.C0 * CFrame.Angles(0,.5,1)
        LS.C0 = LS.C0 * CFrame.Angles(0,-.5,-1)

local       x = Instance.new("Part", Character)
            x.CFrame = Torso.CFrame * CFrame.new(0,-5,-5)
            x.Shape = "Ball"
            x.BrickColor = BrickColor.new("Teal")
            x.Size = x.Size + Vector3.new(1,1,1)
            x.Anchored = true
            x.TopSurface = 0
            x.BottomSurface = 0
            x.Material = "Concrete"
local       s = Instance.new("ParticleEmitter", x)
            s.LightEmission = 100
            s.Transparency = 0.2
            s.Rate = 10
            s.VelocitySpread = 100000
        end



end)


Mouse.KeyUp:connect(function(key)
    key = key:lower()
    if key == "v" then
        hold = false
    end
end)

Mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "p" then
        for i = 1, 4 do
            wait(0.00001)
            RS.C0 = RS.C0*CFrame.Angles(0,0,5)
            LS.C0 = LS.C0*CFrame.Angles(0,0,-5)
        end
    end
end)
0
any errors? BringUpon 25 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

What cause this?

Why aren't my scripts running in the server? Easy Answer, Because Some scripts will run before the player is even in the game, casting an error.

How do I stop this?

How do I stop this madness? Well you can use the WaitForChild or repeat wait() until childName.

What is WaitForChild?

WaitForChild, yields the current thread, if a child with the given title, then returns the child, and Continues on. What if the Child didn't exist, then your code(code below WaitForChild) will not run at all.

Player = game.Players.LocalPlayer

repeat wait() until Player.Character

Character = Player.Character
Torso = Character:WaitForChild("Torso")
Mouse = Player:GetMouse()
RS = Torso["Right Shoulder"]
LS = Torso["Left Shoulder"]
hold = false
f = script.Parent

Mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "v" then
        RS.C0 = RS.C0 * CFrame.Angles(0,.5,1)
        LS.C0 = LS.C0 * CFrame.Angles(0,-.5,-1)

local       x = Instance.new("Part", Character)
            x.CFrame = Torso.CFrame * CFrame.new(0,-5,-5)
            x.Shape = "Ball"
            x.BrickColor = BrickColor.new("Teal")
            x.Size = x.Size + Vector3.new(1,1,1)
            x.Anchored = true
            x.TopSurface = 0
            x.BottomSurface = 0
            x.Material = "Concrete"
local       s = Instance.new("ParticleEmitter", x)
            s.LightEmission = 100
            s.Transparency = 0.2
            s.Rate = 10
            s.VelocitySpread = 100000
        end



end)


Mouse.KeyUp:connect(function(key)
    key = key:lower()
    if key == "v" then
        hold = false
    end
end)

Mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "p" then
        for i = 1, 4 do
            wait(0.00001)
            RS.C0 = RS.C0*CFrame.Angles(0,0,5)
            LS.C0 = LS.C0*CFrame.Angles(0,0,-5)
        end
    end
end)

0
Thia is an exact copy of a previously posted answer. No effort = no upvote. unmiss 337 — 9y
0
Actually I got the WaitForChild from "TheContinentofEurope", If I had no effort you should post an answer. BringUpon 25 — 9y
0
Exactly, you copied it. unmiss 337 — 9y
0
doesn't work. tyler46783 0 — 9y
Ad

Answer this question