so i made a script that checks if the player have a tool that is named like “object [object leaderstat value]” anyway when i don’t have the tool it adds it up, but i don’t want the tool come back where the value is 0, how would i do that? i tried checking if the name is wood[0] but it still don’t work
local change = game.ReplicatedStorage.Change
local wood = change.Wood
local woodp = change.Woodp
local rock = change.Rock
local rockp = change.Rockp
local metal = change.Metal
local metalp = change.Metalp
local glass = change.Glass
local craft = change.Table
wood.OnServerEvent:Connect(function(plr)
if not plr.Character:FindFirstChild("Wood ["..plr.Resources.Wood.value.."]") and not plr.Backpack:FindFirstChild("Wood ["..plr.Resources.Wood.value.."]") and not plr.Backpack:FindFirstChild("Wood [0]") and not plr.Character:FindFirstChild("Wood [0]") then
local clone = game.ReplicatedStorage.Wood:Clone()
clone.Parent = plr.Backpack
end
end)
if name ~= wood[0] then --[[Good]] else --[[Bad]] end
I think all you need is to use the ~= operation! You can use this to check if your variable is not equal to nil.
For example:
if name ~= nil then
print("Ran")
end
where would i use the name…? isn’t finding the object equal to finding it’s name
I was just using that as an example. You could also say:
if wood ~= nil then print("Ran") end
I’m not sure what variable you’re trying to check with your code, as I’m not really sure what you’re trying to accomplish.
If you’re trying to check to see if the player has a tool, you can check if the tool is a child of the player’s character.
local character = plr.Character
local tool = character:FindFirstChild("Axe")
if tool ~= nil then
print("Ran")
end
Or put the script directly inside the tool, and check if script.Parent.Parent.ClassName == "Model"
Again, your wording in your initial post was a bit confusing, so I’m unsure what you’re trying to accomplish here.
Doesnt nil mean nothing meaning its value is useless or not used
1 Like
Nil does pretty much mean nothing, but you can use it to check if something exists.
Edit: Here’s the article on nil, if you’re curious: Nil Values
Also your trying to create a OnServerEvent? is the wood a remoteEvent?
so there are leaderstats
and the tools’s name changes with it, like when the leaderstat is 2 the tool name would be
wood [2]
and i am trying to make it stop giving me the tool when it is 0, which means when i use the tool, the tool finds out it is 0 and destroys itself, and not coming back until it is more than 0, but the current script gives me the tool regardless
lowercae wood is a remote event, and Wood is a tool in rep storage
Okay, thanks for the explanation.
Do you already have a script that successfully names the tool?
if you want it to stop giving it when its 0 do
if plr.Resources.Wood.value <= 0 then
-- do stuff
end
still confused on what your trying to achieve here
yes, it already know how to find the tool and detect its there or not, i just wanna make it stop giving me it if its 0…i just had an idea brb
oh ye lemme try this
local change = game.ReplicatedStorage.Change
local wood = change.Wood
local woodp = change.Woodp
local rock = change.Rock
local rockp = change.Rockp
local metal = change.Metal
local metalp = change.Metalp
local glass = change.Glass
local craft = change.Table
wood.OnServerEvent:Connect(function(plr)
if not plr.Character:FindFirstChild("Wood ["..plr.Resources.Wood.value.."]") and not plr.Backpack:FindFirstChild("Wood ["..plr.Resources.Wood.value.."]") and .plr.Resources.Wood.value ~= 0 then
local clone = game.ReplicatedStorage.Wood:Clone()
clone.Parent = plr.Backpack
end
end)
i would define character so it would be easier for you to get things from characters instances
Okay. I think you might be making this issue more complex than it needs to be.
After you figure out what name the tool needs to be, just put a simple if statement to check if the name is not wood [0].
thats what i did lol, check my oringinal post
nope still don’t work, it dosn’t work now
wood.OnServerEvent:Connect(function(plr)
local Character = plr.Character or plr.CharacterAdded:Wait()
for _, v in pairs(Character:GetChildren()) do
if Character:FindFirstChild("Wood ["..plr.Resources.Wood.value.."]") and plr.Resources.Wood.value > 1 then
-- do stuff
elseif not Character:FindFirstChild("Wood ["..plr.Resources.Wood.value.."]") and plr.Resources.Wood.value > 1 then
-- do stuff
end
end
end)
try this maybe