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

How do you define a IntValue in a player as a variable?

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

3 answers

✓ Accepted answer

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!

1 comment

0

Oh, I meant I need to clone something into the player's backpack based on it's value. (edited question). Sorry!

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! ;)

3 comments

1

You should explain how (if it does) your code works so they can learn, not toss them a script.

0

There you go. I added a couple more comments, and if they have a question they should just ask. Nobody's perfect.

0

Too many comments hurt readability. It would be better to explain how this works from outside the code block.

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