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

Script not working in-game?

This works in studio but not in game.

local Player = game.Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera
local SS = game:WaitForChild("ServerStorage")
local Crate = SS.Crate
Ready = true
function OnClick()
if Ready == true then
Ready = false
local Pad = Instance.new("Part")
Pad.Name = "CrateLand"
Pad.Size = Vector3.new(5, 5, 5)
Pad.Anchored = true
Pad.CanCollide = false
Pad.Transparency = 0.5
Pad.BrickColor = BrickColor.new("Bright red")
Pad.Position = Vector3.new(Player.Character.Torso.Position.X +10, Player.Character.Torso.Position.Y, Player.Character.Torso.Position.Z)
Pad.Parent = Camera
local CrateCopy = Crate:Clone()
CrateCopy.PrimaryPart = CrateCopy.Main
CrateCopy.PrimaryPart.Position = Vector3.new(Camera.CrateLand.Position.X, Camera.CrateLand.Position.Y + 50, Camera.CrateLand.Position.Z)
CrateCopy.Parent = Camera
wait(5)
Camera:FindFirstChild("CrateLand"):Destroy()
Ready = true
end
end
script.Parent.MouseButton1Click:connect(OnClick)

3 comments

0

You can't use LocalPlayer in a regular script, it must be in a local script!

0

Nor can you use CurrentCamera in a regular script, it must also be in a local script!

0

It is a local script.

1 answer

Ah Yes, This Error Is Quite Annoying...

I've encounter this error multiple times and have not been able to figure it out. You see, whenever you start a game, the script is auto loaded, so it pretty much loads so quickly, it doesn't work. All you have to do is use the nifty code; WaitForChid, WaitForChild is a useful function to have the script Wait for the child of the object and then execute the code. So to insert it into your code above, you're gonna have to insert it into the variables. Such as this

local Camera = game.Workspace:WaitForChild("CurrentCamera")--This will wait until the 'CurrentCamera' is ready.

So just like you did with ServerStorage, you have to do this with game.Players.LocalPlayer, SS.Crate, etc.

GreekGodOfMLG

1 comment

0

I added this and now none of the script will work in-game or in studio with no output.

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