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

IntValues and Addition?

Asked by 8 years ago

This is one of the scripts

part=script.Parent


function collect(part1)
    part:Destroy()
    print("bob")
    part1.Item.Coke.Value+1

end

part.ClickDetector.MouseClick:connect(collect)

Here is another.

game.Players.PlayerAdded:connect(function(player)
    local Item= Instance.new("Model")
    Item.Name = "Item"
    Item.Parent=player
    wait(1)
    local Coke=Instance.new("IntValue")
    Coke.Name="Coke"
    Coke.Parent=player.Item

    Coke.Value=0
end)

So basically what the first script wants is when you click the part it destroys itself and also adds a value to the player What the second one does is add a value into the player and this is the value that the first scripts adds onto. So the problem is it wont add. The addition sign in the first script has a red line under it but thats all i know.

0
Try putting "part:Destroy()" last in the function. GoldenPhysics 474 — 8y

2 answers

Log in to vote
2
Answered by
Kryddan 261 Moderation Voter
8 years ago

To use addition to IntValues and all of that stuff you have to do it like this part1.Item.Coke.Value = part1.Item.Coke.Value + 1.

And I am pretty sure that after you destroy the part where the script is held, the rest of the code won't execute.

Ad
Log in to vote
0
Answered by
Mystdar 352 Moderation Voter
8 years ago

First script

Your function "collect" has a parameter called "part1" so when calling it you have to define the parameter, silly!

part.ClickDetector.MouseClick:connect(collect) -- NO PARAMETER
part.ClickDetector.MouseClick:connect(collect(--[[WHATEVER YOU WANT part1 TO BE]]))

Hehe

Otherwise line 4 of your function is not acting on anything and breaking the code, since Part1 is not defined

Second script

Item is a variable in your code as well as an item in the player so when calling

player.Item

Since you defined "Item" as "the player that joined's item" you are actually doing:

Player.Player.Item

Instead do

.Parent = Item

Answer this question