generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Convert Penny to Nickel

Previous Thread :: Next Thread 
computercris12 is not online. computercris12
Joined: 14 Nov 2011
Total Posts: 327
24 Nov 2011 02:29 PM
I want to make a script that onTouched it changes 5 pennies to 1 nickel...


Here is my LeaderBoard script:


print("Cash Stuffs running!")

function onPlayerEntered(newPlayer)
wait(.5)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local stats2 = Instance.new("IntValue")
stats2.Name = "Tycoon"

local cash = Instance.new("IntValue")

cash.Name = "Money"
cash.Value = 0 --This sets the amount of money every player starts with

local coin = Instance.new("IntValue")

coin.Name = Penny
coin.Value = 100

local coin = Instance.new("IntValue")

coin1.Name = Nickle
coin1.Value = 0

local coin = Instance.new("IntValue")

coin2.Name = Dime
coin2.Value = 0

local coin = Instance.new("IntValue")

coin3.Name = Quarter
coin3.Value = 0


cash.Parent = stats
coin.Parent = stats
coin1.Parent = stats
coin2.Parent = stats
coin3.Parent = stats
stats2.Parent = newPlayer
stats.Parent = newPlayer

end

game.Players.ChildAdded:connect(onPlayerEntered)

----------------------------------------------

I dont want to change this script, I wawnt to make a button that when touched it changes Pennies to nickels. Please help!
Report Abuse
BobGeorgenworn909 is not online. BobGeorgenworn909
Joined: 03 Apr 2008
Total Posts: 1161
24 Nov 2011 02:35 PM
script.Parent.Touched:connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
p = game.Players:FindFirstChild(h.Parent.Name)
n = p.leaderstats.Nickle.Value
pen = p.leaderstats.Penny.Value
for i = 1, n do
n = n - 1
p = p + 5
end
end
end)


This should work, except you need Quotations "" around the names of the stats in your leaderboard script
Report Abuse
computercris12 is not online. computercris12
Joined: 14 Nov 2011
Total Posts: 327
24 Nov 2011 02:36 PM
huh?
Report Abuse
BobGeorgenworn909 is not online. BobGeorgenworn909
Joined: 03 Apr 2008
Total Posts: 1161
24 Nov 2011 02:37 PM
Put the script I made into a brick that you want to touch.


Also, here is the fixed version of your script:

print("Cash Stuffs running!")

function onPlayerEntered(newPlayer)
wait(.5)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local stats2 = Instance.new("IntValue")
stats2.Name = "Tycoon"

local cash = Instance.new("IntValue")

cash.Name = "Money"
cash.Value = 0 --This sets the amount of money every player starts with

local coin = Instance.new("IntValue")

coin.Name = "Penny"
coin.Value = 100

local coin = Instance.new("IntValue")

coin1.Name = "Nickle"
coin1.Value = 0

local coin = Instance.new("IntValue")

coin2.Name = "Dime"
coin2.Value = 0

local coin = Instance.new("IntValue")

coin3.Name = "Quarter"
coin3.Value = 0


cash.Parent = stats
coin.Parent = stats
coin1.Parent = stats
coin2.Parent = stats
coin3.Parent = stats
stats2.Parent = newPlayer
stats.Parent = newPlayer

end

game.Players.ChildAdded:connect(onPlayerEntered)
Report Abuse
nightname is not online. nightname
Joined: 10 Jun 2008
Total Posts: 8960
24 Nov 2011 02:39 PM
This title is called "Convert Penny to Nickel", but you name the Nickel value "Nickle"? I am guessing that is a typo. Nevertheless, I will create the script for you.

Put this script inside a block:

local Block = script.Parent;

Block.Touched:connect(function(stim)
if stim.Parent:findFirstChild("Humanoid") == true then
local Player = Game.Players:GetPlayerFromCharacter(stim.Parent);
while Player.leaderstats.Penny >= 5 then
Player.leaderstats.Penny = Player.leaderstats.Penny - 5;
Player.leaderstats.Nickle = Player.leaderstats.Nickle + 1;
wait()
end
end
end)
Report Abuse
BobGeorgenworn909 is not online. BobGeorgenworn909
Joined: 03 Apr 2008
Total Posts: 1161
24 Nov 2011 02:41 PM
Oops, I read it wrong, I thought it was convert nickel to penny :/
Report Abuse
computercris12 is not online. computercris12
Joined: 14 Nov 2011
Total Posts: 327
24 Nov 2011 02:42 PM
@Night
Yes it was a typo...

@Both

ty i wil try both of them.
Report Abuse
computercris12 is not online. computercris12
Joined: 14 Nov 2011
Total Posts: 327
24 Nov 2011 02:46 PM
I want to take out the Tycoon Part of this script what would it look like?
Report Abuse
computercris12 is not online. computercris12
Joined: 14 Nov 2011
Total Posts: 327
24 Nov 2011 02:49 PM
@Night

There is a flaw in your script:

local Block = script.Parent;

Block.Touched:connect(function(stim)
if stim.Parent:findFirstChild("Humanoid") == true then
local Player = Game.Players:GetPlayerFromCharacter(stim.Parent);
while Player.leaderstats.Penny >= 5 then
Player.leaderstats.Penny = Player.leaderstats.Penny - 5;
Player.leaderstats.Nickle = Player.leaderstats.Nickle + 1;
wait()
end
end
end)

-----Your Script ^^^^^^^^----------

flaw: Line 6 do, expected near then...


------Fixed Script:

local Block = script.Parent;

Block.Touched:connect(function(stim)
if stim.Parent:findFirstChild("Humanoid") == true then
local Player = Game.Players:GetPlayerFromCharacter(stim.Parent);
while Player.leaderstats.Penny >= 5 do
Player.leaderstats.Penny = Player.leaderstats.Penny - 5;
Player.leaderstats.Nickle = Player.leaderstats.Nickle + 1;
wait()
end
end
end)
Report Abuse
nightname is not online. nightname
Joined: 10 Jun 2008
Total Posts: 8960
24 Nov 2011 02:51 PM
I cannot believe I did not notice that mistake. I look at the things I write twice, just in case I have typos. I guess you cannot actually notice your own mistakes....
Report Abuse
computercris12 is not online. computercris12
Joined: 14 Nov 2011
Total Posts: 327
24 Nov 2011 02:52 PM
Apparently not, o btw how would i inquire my leaderboard script without the tycoon part?
Report Abuse
nightname is not online. nightname
Joined: 10 Jun 2008
Total Posts: 8960
24 Nov 2011 03:00 PM
Sorry I took time to answer, I was trying to replicate a 3D Shape I saw today.

print("Cash Stuffs running!")

function onPlayerEntered(newPlayer)
wait(.5)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"

local cash = Instance.new("IntValue")

cash.Name = "Money"
cash.Value = 0 --This sets the amount of money every player starts with

local coin = Instance.new("IntValue")

coin.Name = "Penny"
coin.Value = 100

local coin = Instance.new("IntValue")

coin1.Name = "Nickle"
coin1.Value = 0

local coin = Instance.new("IntValue")

coin2.Name = "Dime"
coin2.Value = 0

local coin = Instance.new("IntValue")

coin3.Name = "Quarter"
coin3.Value = 0


cash.Parent = stats
coin.Parent = stats
coin1.Parent = stats
coin2.Parent = stats
coin3.Parent = stats
stats.Parent = newPlayer

end

game.Players.ChildAdded:connect(onPlayerEntered)
Report Abuse
computercris12 is not online. computercris12
Joined: 14 Nov 2011
Total Posts: 327
24 Nov 2011 03:04 PM
It didnt give me my stats.
Report Abuse
nightname is not online. nightname
Joined: 10 Jun 2008
Total Posts: 8960
24 Nov 2011 03:06 PM
Then that means your Leaderboard script does not work from the very beginning?
Report Abuse
computercris12 is not online. computercris12
Joined: 14 Nov 2011
Total Posts: 327
24 Nov 2011 03:07 PM
Then how do i fix that?
Report Abuse
nightname is not online. nightname
Joined: 10 Jun 2008
Total Posts: 8960
24 Nov 2011 03:18 PM
Sorry, I was still doing something else. Anyway, I noticed I have forgotten values.

Here is the script which you insert into the block:

local Block = script.Parent;

Block.Touched:connect(function(stim)
if stim.Parent:findFirstChild("Humanoid") then
local Player = Game.Players:GetPlayerFromCharacter(stim.Parent);
while Player.leaderstats.Penny.Value >= 5 do
Player.leaderstats.Penny.Value = Player.leaderstats.Penny.Value - 5;
Player.leaderstats.Nickle.Value = Player.leaderstats.Nickle.Value + 1;
wait()
end
end
end)

------------------

Here is the script which you insert into the workspace:


print("Cash Stuffs Running")

function onPlayerEntered(newPlayer)
wait(.5)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"

local cash = Instance.new("IntValue")

cash.Name = "Money"
cash.Value = 0 --This sets the amount of money every player starts with

local coin = Instance.new("IntValue")

coin.Name = "Penny"
coin.Value = 100

local coin1 = Instance.new("IntValue")

coin1.Name = "Nickle"
coin1.Value = 0

local coin2 = Instance.new("IntValue")

coin2.Name = "Dime"
coin2.Value = 0

local coin3 = Instance.new("IntValue")

coin3.Name = "Quarter"
coin3.Value = 0


cash.Parent = stats
coin.Parent = stats
coin1.Parent = stats
coin2.Parent = stats
coin3.Parent = stats
stats.Parent = newPlayer

end

game.Players.PlayerAdded:connect(onPlayerEntered)
Report Abuse
nightname is not online. nightname
Joined: 10 Jun 2008
Total Posts: 8960
24 Nov 2011 03:26 PM
Has my solution worked? As I double checked, and I am pretty sure there is no more errors.
Report Abuse
computercris12 is not online. computercris12
Joined: 14 Nov 2011
Total Posts: 327
24 Nov 2011 03:27 PM
It worked. Both of them...

to change this script would i just do this

Original:

local Block = script.Parent;

Block.Touched:connect(function(stim)
if stim.Parent:findFirstChild("Humanoid") then
local Player = Game.Players:GetPlayerFromCharacter(stim.Parent);
while Player.leaderstats.Penny.Value >= 5 do
Player.leaderstats.Penny.Value = Player.leaderstats.Penny.Value - 5;
Player.leaderstats.Nickle.Value = Player.leaderstats.Nickle.Value + 1;
wait()
end
end
end)

Mine:

local Block = script.Parent;

Block.Touched:connect(function(stim)
if stim.Parent:findFirstChild("Humanoid") then
local Player = Game.Players:GetPlayerFromCharacter(stim.Parent);
while Player.leaderstats.Nickle.Value >= 2 do
Player.leaderstats.Penny.Value = Player.leaderstats.Nickle.Value - 2;
Player.leaderstats.Nickle.Value = Player.leaderstats.Dime.Value + 1;
wait()
end
end
end)


or would it be different?
Report Abuse
nightname is not online. nightname
Joined: 10 Jun 2008
Total Posts: 8960
24 Nov 2011 03:30 PM
I do not understand what you are doing...

"Player.leaderstats.Penny.Value = Player.leaderstats.Nickle.Value - 2;"

You are changing the Penny's value to the Nickle's value with a subtraction of 2? I am guessing you are trying to do this:

Player.leaderstats.Nickle.Value = Player.leaderstats.Nickle.Value - 2;
Player.leaderstats.Dime.Value = Player.leaderstats.Dime.Value + 1;

------

All that does is for every 2 Nickels, you get 1 Dime.
Report Abuse
computercris12 is not online. computercris12
Joined: 14 Nov 2011
Total Posts: 327
24 Nov 2011 03:32 PM
Yes, my misread of the script, that is what i a trying to do.
"All that does is for every 2 Nickels, you get 1 Dime."

Thank you, would i change all of those to fit my oter currencies?

and what would i do to Reverse the effect?
Report Abuse
nightname is not online. nightname
Joined: 10 Jun 2008
Total Posts: 8960
24 Nov 2011 03:37 PM
"Thank you, would i change all of those to fit my oter currencies?"

I guess so, but I would use a function to change it for me to my desired state of value.

"what would i do to Reverse the effect?"

The reverse effect is much simpler. All you have to do is check if the value is 1 or more, and multiply it.

Report Abuse
computercris12 is not online. computercris12
Joined: 14 Nov 2011
Total Posts: 327
24 Nov 2011 03:41 PM
I have finished out the Converting from small to large.

May you do the first Reverse script for me please?

And Where would i put the script:

while true do
coin.Value = coin.Value + 5
wait(.5)
end
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
24 Nov 2011 03:42 PM
Yes, that would work, to reverse it,you could do something like this:
if dime.Value > 0 then
Nickel.Value = Dime.Value * 2
Dime.Value = 0

might wanna debouncer so it doesn't give too many nickels.
Report Abuse
computercris12 is not online. computercris12
Joined: 14 Nov 2011
Total Posts: 327
24 Nov 2011 03:45 PM
.... i am no good with debouncers. xD and i am barely able to do this.

On a ranking scale of Scripting I would be:

The lowest of the lowest of the low scripter
Report Abuse
nightname is not online. nightname
Joined: 10 Jun 2008
Total Posts: 8960
24 Nov 2011 03:46 PM
The reverse would look like this:

while Player.leaderstats.Nickle.Value >= 5 do
Player.leaderstats.Penny.Value = Player.leaderstats.Penny.Value + 5;
Player.leaderstats.Nickle.Value = Player.leaderstats.Nickle.Value - 1;

--------
The person who said you would need a "debouncer", he is incorrect.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image