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

Leaderstat value is nil ?

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.

9 comments

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

0

Thx.

0

Dont use .Value in a variable. Try doing Level.Value on line 9.

0

Thanks dinoz but it doesn't work.

0

Thats not your only issue, just pointing out something that needed to be corrected.

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"

0

Also, is this only one script with all this code in it?

0

Thats also confusing me Xpol.

0

One script ? Yeah.

2 answers

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

1 comment

0

So ? How do i fix it ? Should i add the function "onTouched in the remote event ?

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.

3 comments

0

Doesn't solve his problem

0

(thinks)

0

What do you mean about "code" ?

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