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

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

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)

1 comment

0

any errors?

1 answer

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)

4 comments

0

Thia is an exact copy of a previously posted answer. No effort = no upvote.

0

Actually I got the WaitForChild from "TheContinentofEurope", If I had no effort you should post an answer.

0

Exactly, you copied it.

0

doesn't work.

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