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

How could this weapon script be fixed?

Asked by 10 years ago

The Error i get is: attempt to compare nil with a number. The line i get the error is:

if LeftButtonDownTime and currTime - LeftButtonDownTime > Start(THROW) and--WHAT WRONG?
urrTime - LeftButtonDownTime < 1.15 then
ThrowAttack()
local SLASH_DAMAGE = 25
local DOWNSTAB_DAMAGE = 25
local Damage = 25
local SPEED = 85
local THROW = 0.38
local THROWING_DAMAGE = 100

--WHAT AM I DOING WRONG?
function Start()
if Game.Players.LocalPlayer.PlayerGui.Default.Value == true then
SLASH_DAMAGE = 25
DOWNSTAB_DAMAGE = 25
Damage = 25
SPEED = 85
THROW = 0.38
elseif Game.Players.LocalPlayer.PlayerGui.Upgrade2.Value == true then
SLASH_DAMAGE = 30
elseif Game.Players.LocalPlayer.PlayerGui.Upgrade3.Value == true then
DOWNSTAB_DAMAGE = 30
elseif Game.Players.LocalPlayer.PlayerGui.Upgrade4.Value == true then
Damage = 30
elseif Game.Players.LocalPlayer.PlayerGui.Upgrade5.Value == true then
SPEED = 100
SLASH_DAMAGE = 50
DOWNSTAB_DAMAGE = 50
Damage = 50
elseif Game.Players.LocalPlayer.PlayerGui.Upgrade7.Value == true then
SPEED = 125
elseif Game.Players.LocalPlayer.PlayerGui.Upgrade8.Value == true then
THROW = 0.19
end
end

THIS IS NOT FULL SCRIPT, JUST EXAMPLE AND WHERE THE ERROR IS!

1 answer

Log in to vote
0
Answered by 10 years ago

First off, on the first line currTime is undefined. I'm assuming you defined that elsewhere, but I thought I should say it anyway. Secondly you aren't using the function arguments in your Start() function so when you call it on the first line with Start(throw) the (throw) isn't actually doing anything. Thirdly, in order for the Start(throw) line to actually give anything to the logic of line one (and this is probably why you are getting the nil) you have to use "return THROW". I think you got this mixed up with using function arguments. example:

function throw()
    throw = 2
    return throw
end

print(throw()) -- prints 2
function throw(x)
    throw = 2*x
    return throw()
end

print(throw(2)) -- prints 4
Ad

Answer this question