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.
How would I make a script that can tell if a value has a certain amount and do something?
3 answers
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)
1 comment
good, but what event?
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!
1 comment
I want to make it so if the value is at 50, it will print something and then I can do the rest.
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
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
I want to make it so if its at for example 50, it will print something or change something.
I love playing miners haven