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

Leaderstat value is nil ?

Asked by 5 years ago
Edited 5 years ago

Soooo. This problem is a time dissolver. I'm trying to do a game (rpg) with abilities and skills BUT , there is the thing : There's a level system and i wish the abilities to evolve with the level... There's the script... :(

local repstore = game:WaitForChild("ReplicatedStorage")
local Remote = repstore.OFA:WaitForChild("Punch")

Remote.OnServerEvent:connect(function(player) 
    LDS = player:FindFirstChild("leaderstats")
    Level = LDS.Level
end)

function onTouched(hit)
    local human = hit.Parent:FindFirstChild("Humanoid")
    if (human ~= nil ) and debounce == false and human ~= script.Parent.Parent.Humanoid then
        human:TakeDamage(Level.Value * 3)
        local position = Instance.new("BodyVelocity",hit.Parent.HumanoidRootPart)
        position.MaxForce = Vector3.new(999999999999999,9999999999999,999999999999999)
        position.P = 300
        position.Velocity = script.Parent.Parent:FindFirstChild("LowerTorso").CFrame.UpVector * 5
        game.Debris:AddItem(position,0.1)
        script.Disabled = true
        debounce = true
        wait(1)
        debounce = false
    end
end

script.Parent.Touched:connect(onTouched)
local repstore = game:WaitForChild("ReplicatedStorage")
local Remote = repstore.OFA:WaitForChild("Punch")

Remote.OnServerEvent:connect(function(player) 
    LDS = player:FindFirstChild("leaderstats")
    Level = LDS.Level
end)

(This part was used to get local player)

The attack deals damage but when i increase the level, attack damage don't increase. My life is a entire nightmare because of this.

Any help is accepted. Thanks for reading. Arthas.

EDIT : This script goes with an other one :

local repstore = game:WaitForChild("ReplicatedStorage")
local Remote = repstore.OFA:WaitForChild("Punch")



Remote.OnServerEvent:connect(function(player) 
    LArm = player.Character:WaitForChild("LeftLowerArm") 
        RArm = player.Character:WaitForChild("RightLowerArm")
local human = player.Character:FindFirstChild("Humanoid")
local canattack = true 
        local Damage2 = script.Damage:Clone()
        Damage2.Parent = RArm
        canattack = false
        human:LoadAnimation(script.L):Play()
        Damage2.Disabled = false
        wait(0.6)
        Damage2:Destroy()
        canattack = true
        end)

EDIT2 : I think i do everything wrong because of my unexpericence with lua.

0
Don't know if you just forgot to add it but you need an "end)" at the end + a tip: only have 1 remoteEvent and add more variables defined when calling the remoteEvent, that way you can have tons of event with only 1 RemoteEvent, and that means less lag stef0206 125 — 5y
0
Thx. AKT_Arthas 2 — 5y
0
Dont use .Value in a variable. Try doing Level.Value on line 9. DinozCreates 1070 — 5y
0
Thanks dinoz but it doesn't work. AKT_Arthas 2 — 5y
View all comments (5 more)
0
Thats not your only issue, just pointing out something that needed to be corrected. DinozCreates 1070 — 5y
0
This question was edited and his OnServerEvent included a line that went like "Level = LDS.Level". I'm assuming this should actually be "Level = LDS.Level + 1" xPolarium 1388 — 5y
0
Also, is this only one script with all this code in it? xPolarium 1388 — 5y
0
Thats also confusing me Xpol. DinozCreates 1070 — 5y
0
One script ? Yeah. AKT_Arthas 2 — 5y

2 answers

Log in to vote
0
Answered by
stef0206 125
5 years ago

In the onTouched function you never call call the RemoteEvent therefor the script doesn't know what level you are

0
So ? How do i fix it ? Should i add the function "onTouched in the remote event ? AKT_Arthas 2 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

There is no need to do ["Level"], you can simply do Level. Object names in brackets usually have more than one word in their name, which is why they have brackets. Lua can't detect an object name with more than one word without brackets.

As for a nil debunk-er:

local level = LDS:FindFirstChild("Level")
if level then
    -- Code
end

This should fix your problem, as it checks to see if the value actually exists or not. If it doesn't, the script stops.

0
Doesn't solve his problem User#24403 69 — 5y
0
(thinks) DeceptiveCaster 3761 — 5y
0
What do you mean about "code" ? AKT_Arthas 2 — 5y

Answer this question