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 7 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 — 7y
0
I want to make it so if its at for example 50, it will print something or change something. SGYTMinersHaven -16 — 7y
0
I love playing miners haven greatneil80 2647 — 7y

3 answers

Log in to vote
0
Answered by 7 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:

1local TheValueObject = game.Workspace.NumberValue --This is where you have the little value object
2 
3Event:Connect(function() --The event that makes it want the check the value
4if TheValueObject.Value == TheNumberYouWant then --This is where you check to see if the value is what you want
5 
6--This is where you have it do the stuff
7 
8end)
0
good, but what event? SGYTMinersHaven -16 — 7y
Ad
Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
7 years ago

Hello, SGYTMinersHaven!

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

Example:

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

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

Example:

1-- Let's say if the script is a child of the value
2-- The script will add 1 to the value
3script.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 — 7y
Log in to vote
0
Answered by 7 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 <)

01game.Players.PlayerAdded:connect(function(player)
02     local leaderstats = Instance.new("IntValue")
03     leaderstats.Name = "leaderstats"
04     leaderstats.Parent = player
05 
06     local money = Instance.new("IntValue") --We create a new IntValue
07     money.Name = "Money" --this is the name you want the leader-stat to be when it shows up in-game.
08     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)
09     money.Parent = leaderstats -- Set the money object as a child of the leaderstats object.
10 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)

01local player = game.Players.LocalPlayer
02local uis = game:GetService("UserInputService")
03local value = 50 -- Money Need to active this function
04 
05uis.InputBegan:Connect(function(key)
06    if key.KeyCode == Enum.KeyCode.V then
07        if player.leaderstats.Money.Value < value then return end
08        print("Player Have Acess")
09        if not player.leaderstats.Money.Value < value then
10            print("Player dont have acess")
11        end
12    end
13end)

Answer this question