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

FlashLight script not working?

Asked by 8 years ago

The Propose of the script is to give a player a spotlight, and then count down a battery number value to 0, then disable the light. But it unfortunately its not working, any idea why? Code:

local plr = game.Players.LocalPlayer
local char = plr.Character
local sp = script.Parent
local mouse =plr:GetMouse()
L = Instance.new("SpotLight")
L.Parent = char.Torso
L.Brightness = 10
L.Range = 20
if sp.Parent.Battery ~= nil then
    while sp.Parent.Battery.Value = 0< do
        sp.Parent.Battery.Value = sp.Parent.Battery.Value -1
    until sp.Parent.Battery.Value = 0
    if sp.Parent.Battery.Value = 0 then
        char.Torso.SpotLight.Enabled = false
    end
end

1 answer

Log in to vote
0
Answered by
Ryzox 220 Moderation Voter
8 years ago

If you would ever check the output the error would be quite obvious, but anyway here's what's wrong:

On line 10 I'm not sure what you're doing e.e but I think you meant:

while sp.Parent.Battery.Value > 0 do

Which will take 1 off the battery value WHILE the battery value is greater than 0

You are also using until wrong because you have no repeat anywhere so i'm not sure what you're trying with that.

I think what you're attempting to do is this:

local plr = game.Players.LocalPlayer
repeat wait() until plr.Character -- waiting until character exists
local char = plr.Character
local sp = script.Parent
local mouse =plr:GetMouse()
L = Instance.new("SpotLight", char.Torso)
L.Brightness = 10
L.Range = 20
if sp.Parent.Battery.Value ~= nil then
    repeat -- takes 1 off battery every 1 second until the battery is equal to 0 then disables spotlight
        sp.Parent.Battery.Value = sp.Parent.Battery.Value -1
    wait(1)
    until sp.Parent.Battery.Value == 0
    char.Torso.SpotLight.Enabled = false
end
0
its still not changing for me pluginfactory 463 — 8y
Ad

Answer this question