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

How can I add 'Light' inside of a model ?

The title doesn't mean I want to insert it all, it's easy, but I want to add it via Instance.new way. So far I've come up with this:

Light = script.Parent.Light
Cannon = script.Parent.Pyro

function OnTouched()
	Light.BrickColor = BrickColor.new("Bright red")
	FireLight = Instance.new("SurfaceLight")
	FL = FireLight
	FL.Range = 12.5
	FL.Face = "Top"
	FL.Brightness = 5
	FL.Angle = 180
	FL.Shadows = false
	FL.Color = Color3.new(255, 0, 0)
	FL.Position = Light.Position
	FL.Parent = Light
end

Cannon.Touched:connect(OnTouched)

I cannot find where's the problem, could any of you help me find it ?

3 comments

0

Function of it is that the light will be inserted if a part 'Cannon' is being touched

0

pls use Color3 instead of BrickColor, e.g, Light.Color3 = Color3.fromRGB(255,0,0) will make a red color

0

The BrickColor is a coloring for a part

1 answer

✓ Accepted answer

As supersmartnoobguy has stated, said light will only be created upon the Cannon part being touched.

I'd like to merely point out a few things. Firstly, you should make it a habit to use local variables, primarily being because they're easier to access (the Lua wiki states that local variables access an array of registers on the stack, as opposed to 'regular' variables indexing a table (if you were interested)). You can read more about the differences here.

You define a local variable by preceding the variable name with the local keyword, as such:

local variable = 'this is a variable'

You're also trying to access a non-existent property of the SurfaceLight. If you look under the properties header, you'll find there's no such property named Position.

On top of this, the Color3.new() constructor uses r, g and b arguments between 0 and 1 - in your case, you'd use the Color3.fromRGB()constructor. However:

Color3.new(255, 0, 0) is the same as Color3.new(1, 0, 0).

You're also assigning a new variable FL to the SurfaceLight being created - you could just remove the 7th line, and replace the 6th line with:

local FL = Instance.new('SurfaceLight')

If you have any issues, let me know!

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