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

Script not working in-game?

Asked by
Zyleak 70
8 years ago

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)
0
You can't use LocalPlayer in a regular script, it must be in a local script! legobuildermaster 220 — 8y
0
Nor can you use CurrentCamera in a regular script, it must also be in a local script! legobuildermaster 220 — 8y
0
It is a local script. Zyleak 70 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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

0
I added this and now none of the script will work in-game or in studio with no output. Zyleak 70 — 8y
Ad

Answer this question