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

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

Asked by 8 years ago
Edited 8 years ago

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

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

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

Ad
Log in to vote
0
Answered by
StoIid 364 Moderation Voter
8 years ago

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!

0
Oh, I meant I need to clone something into the player's backpack based on it's value. (edited question). Sorry! VoidGolem 5 — 8y
Log in to vote
-1
Answered by 8 years ago
Edited 8 years ago

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

1
You should explain how (if it does) your code works so they can learn, not toss them a script. alphawolvess 1784 — 8y
0
There you go. I added a couple more comments, and if they have a question they should just ask. Nobody's perfect. AstrealDev 728 — 8y
0
Too many comments hurt readability. It would be better to explain how this works from outside the code block. Link150 1355 — 8y

Answer this question