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

How do I properly add to an intvalue?

Asked by 5 years ago
Edited 5 years ago

Okay. So I made a part that when someone touches it, the intvalue goes up by 1 and when someone clicks on a button that value goes down by 1. The problem is that after someone clicked that button, the value goes down by 1, but after when someone touched the part to add to the value, it adds up 2 instead of 1. Here is the script in the part:

script.Parent.Touched:Connect(function(hit)
    if script.Parent.Reload.Value == false then
        if hit.Parent:FindFirstChild("Humanoid") ~= nil then
            if script.Parent.Players.Value < 5 then
                script.Parent.Reload.Value = true
                script.Parent.Players.Value = script.Parent.Players.Value +1
`the "Players" is the name of the value`
                hit.Parent.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.BallonPart.Position)
                local gui = game.ReplicatedStorage.ScreenGui:Clone()
                gui.Parent = game.Players:WaitForChild(hit.Parent.Name).PlayerGui
            end
        end
    end
    wait(2)
    script.Parent.Reload.Value = false
end)

and here's the script in the button:

script.Parent.MouseButton1Click:Connect(function()
    game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.SpawnLocation.Position)
    game.Workspace.Part.Players.Value = game.Workspace.Part.Players.Value -1
    script.Parent.Parent.Parent:Destroy()
end)

I think that the 1st script is ignoring the changes made from the 2nd script, so it just keeps adding, but idk how to fix it. Altough the 2nd script isn't ignoring, because it is renewed every time (cloned and destroyed) so it forgets the value of the intvalue.

I'm sure that there is an way out of that and help will be appreciated!

0
You need a debounce in the first script. programmerHere 371 — 5y
0
wait but I've added a debounce in my 1st script TheRealPotatoChips 793 — 5y
0
well it's not enough programmerHere 371 — 5y
0
I thing the 1st script is ignoring the changes made from the 2nd script, so it just keeps adding, but idk how to fix it. TheRealPotatoChips 793 — 5y
View all comments (6 more)
0
Are you using a local script in the second one? Is it meant to be a GUI? programmerHere 371 — 5y
0
yes. TheRealPotatoChips 793 — 5y
0
GUYS PLEASE I NEED SOME HELP TheRealPotatoChips 793 — 5y
0
IntValue.Value = IntValue.Value + x; (with `x` being a number) User#23252 26 — 5y
0
oh so "x" has to be a variable? TheRealPotatoChips 793 — 5y
0
x doesn't have to be a variable; lemme make an answer for you User#23252 26 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

you can set a value of an Int like this:

local intValue = game.bleh.bleh.etc
intValue.Value = intValue.Value + 20 --this will add 20 to the vallue of `intValue`

------------or-------------
local x = 5;
intValue.Value = intValue.Value + x --this will add 5 to the value `IntValue`

you can set the value of an intValue to a new value by doing intValue.Value = 20, <= this will make the value of intValue 20;

doing: intValue.Value = intValue.Value + z basically tells the compiler this: "hey I want you to add the value of z to the value of intValue";

and similarly you can change the values of variables and properties of an object like this.

when you do number = number + X with X being a number, this tells the computer "take thee value of number and add the value of X to the value it

however, doing number = X, will not add the value of X to number, instead, the value of number will be the value of X its like saying "Hey make the value of number equal to the value of X"

example:

local number = 5;
local object = {value = 2};

number = number + 5; --this adds 5 to the value of `number`
print(number) --should print 10 in the output;


object.value = object.value + 4 --adds 4 to the value of `object.value`
print(object.value) --should print 6


number = 20 --sets the value of number to 20
print(number) -- should print 20 in the output..

object.value = 50 --sets object.value to 50
print(object.value) --should print 50

0
But can you like correct my script? Because idk what to do now. TheRealPotatoChips 793 — 5y
Ad

Answer this question