I need to define a Intvalue (gun) in a player as a variable (g), but I can't seem to get it to work. I need to check it's value, then clone something into the player's backpack based on that value. I know how to clone, just not how to check the IntValue since it is in a player. Also, it can't be in a function.
script to clone based off of value:
if g.Value == 0 then game.RepicatedStorage.Weapons.Gun1:clone().Parent = player.Backpack end
What you could attempt to do is change the IntValue
to an ObjectValue
, then make it's value the tool that gets cloned;
local weapons = game.ReplicatedStorage:WaitForChild("Weapons") game.Players.PlayerAdded:connect(function(p) local curTool = Instance.new("ObjectValue",p) curTool.Name = "CurrentTool" p.CharacterAdded:connect(function() if curTool.Value then curTool.Value:Clone().Parent = p.Backpack end end) curTool.Value = weapons:WaitForChild("Gun1") end)
Hope I helped!
~TDP
You can simply check the value of the IntValue, g
by doing a simple print!
print(g.Value)
This should put the value of g
in the output in your studio!
Edited, in order to further explain why this works.
value = g.Value if value == 0 then -- This line just checks to see if the value of g is equal to 0. -- Code if value is 0 - If it is equal to zero, then it runs this code. elseif value == 1 then -- The same thing above is repeated, although instead using one. -- Code if value is 1 elseif value == 2 then -- I think you get the process by now :) -- Code if value is 2 -- Just continue this process. end
If I helped, please remember to upvote! ;)