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

How would I make a script that can tell if a value has a certain amount and do something?

Asked by 6 years ago

So I am making a new game.. And I really need this for it because its a simulator. I dont have any code because I cant seem to get the value of the NumberValue item.

0
Lets Say you have a model and inside the model is the NumberValue item and a script. In the script your gonna right local num = script.Parent.NumberValue.Value That will make num = to the number in the NumberValue Item TheGreatSailor 20 — 6y
0
I want to make it so if its at for example 50, it will print something or change something. SGYTMinersHaven -16 — 6y
0
I love playing miners haven greatneil80 2647 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago

There are a few ways to do this, and it all depends on what you are trying to do. The simplest way to do it is this:

local TheValueObject = game.Workspace.NumberValue --This is where you have the little value object

Event:Connect(function() --The event that makes it want the check the value
if TheValueObject.Value == TheNumberYouWant then --This is where you check to see if the value is what you want

--This is where you have it do the stuff

end)
0
good, but what event? SGYTMinersHaven -16 — 6y
Ad
Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
6 years ago

Hello, SGYTMinersHaven!

To get a VALUE value's you use .Value after the value's position!

Example:

-- Let's say if the script is a child of the value
-- This script will print the value
print(script.Parent.Value)

To set a new value for the VALUE you do like any var!

Example:

-- Let's say if the script is a child of the value
-- The script will add 1 to the value
script.Parent.Value = script.Parent.Value + 1

Good Luck with your games!

0
I want to make it so if the value is at 50, it will print something and then I can do the rest. SGYTMinersHaven -16 — 6y
Log in to vote
0
Answered by 6 years ago

Well, first friend will need a leaderstats to add cash among other things

This an Example : (> https://wiki.roblox.com/index.php?title=Leaderboards <)

game.Players.PlayerAdded:connect(function(player)
     local leaderstats = Instance.new("IntValue")
     leaderstats.Name = "leaderstats"
     leaderstats.Parent = player

     local money = Instance.new("IntValue") --We create a new IntValue
     money.Name = "Money" --this is the name you want the leader-stat to be when it shows up in-game.
     money.Value = 0 --this is the value of money the new player starts out with. To change this, you can add some more code (shown later)
     money.Parent = leaderstats -- Set the money object as a child of the leaderstats object.
 end)

For you to determine if something is activated through Money you can use "<" to determine how much money I need to activate this function

This an Example : (This script will only release this function when the player is 50)

local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local value = 50 -- Money Need to active this function

uis.InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.V then
        if player.leaderstats.Money.Value < value then return end
        print("Player Have Acess")
        if not player.leaderstats.Money.Value < value then
            print("Player dont have acess")
        end
    end
end)

Answer this question