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: Setting a string value from a script

Previous Thread :: Next Thread 
Jackd44 is not online. Jackd44
Joined: 19 Dec 2008
Total Posts: 200
20 Apr 2013 12:41 AM
So what is happening is when the button is touched(Referred to as "BuyBrick") it will output "Already Bought", however, NextIt's value is nil, it has no value. Here is my script, I'll post if I can figure it out before it's solved by you readers.
Report Abuse
Jackd44 is not online. Jackd44
Joined: 19 Dec 2008
Total Posts: 200
20 Apr 2013 12:42 AM
Sorry, forgot to add the code, it's here:

local BuyBrick = script.Parent

function onT(hit)
local m = Instance.new("Message")
local h = hit.Parent:FindFirstChild("Humanoid")
local Buyer = game.Players:playerFromCharacter(hit.Parent)
local NextIt = game.Workspace.ItNext
local buyName = game.Workspace:FindFirstChild("Be it next game - 30")
if h ~= nil then
if Buyer.leaderstats.Points.Value < 30 then
print("Not enough points")
--m.Parent = Buyer
--m.Text = "Sorry, you don't have enough points for this, you need 30!"
--wait(2)
--m:remove()
elseif NextIt.Value ~= nil then
print("Already bought")
--m.Parent = Buyer
--m.Text = "Sorry, somebody else has already bought this, try again next game"
--wait(2)
--m:remove()
else
Buyer.leaderstats.Points.Value = Buyer.leaderstats.Points.Value - 30
NextIt.Value = Buyer.Name
print("Successful!")
--m.Parent = hit.Parent
--m.Text = "Purchase successful! You'll be IT next game.(Refunds not included)"
--wait(2)
--m:remove()
wait(0.5)
end
end
end


BuyBrick.Touched:connect(onT)
Report Abuse
ball360 is not online. ball360
Joined: 31 Mar 2009
Total Posts: 1557
20 Apr 2013 12:44 AM
What is the value type? String, Int?
Report Abuse
Jackd44 is not online. Jackd44
Joined: 19 Dec 2008
Total Posts: 200
20 Apr 2013 12:45 AM
A string, it's empty as well.
Report Abuse
ball360 is not online. ball360
Joined: 31 Mar 2009
Total Posts: 1557
20 Apr 2013 12:48 AM
You're comparing an empty StringValue with nil. Nil means empty. However, an empty StringValue actually holds an empty string, not nil. So:

elseif NextIt.Value ~= "" then
Report Abuse
Jackd44 is not online. Jackd44
Joined: 19 Dec 2008
Total Posts: 200
20 Apr 2013 12:50 AM
Ahhh, ok. Never though nil's worked like that. I thought a nil would be nothing :P
Report Abuse
ball360 is not online. ball360
Joined: 31 Mar 2009
Total Posts: 1557
20 Apr 2013 12:51 AM
Nil is absolutely nothing. However, an empty string is not nil, as it is still a string object. Think of it as comparing empty vacuum (nil) with an empty container (empty string).
Report Abuse
Jackd44 is not online. Jackd44
Joined: 19 Dec 2008
Total Posts: 200
20 Apr 2013 12:54 AM
Hmmm, could I have a pointer to how to set the value when it prints "Successful"? I don't need the whole answer, I just want a pointer so I can learn :)
Report Abuse
ball360 is not online. ball360
Joined: 31 Mar 2009
Total Posts: 1557
20 Apr 2013 01:01 AM
Simply set the value using:
NextIt.Value = "textgoeshere"
Report Abuse
Jackd44 is not online. Jackd44
Joined: 19 Dec 2008
Total Posts: 200
20 Apr 2013 01:03 AM
Ah, sorry. I should have been more specific. I mean how to set it to the name of the person who touched the brick. My line that had
NextIt.Value = Buyer.Name
Didn't seem to work. Any ideas?
Report Abuse
ball360 is not online. ball360
Joined: 31 Mar 2009
Total Posts: 1557
20 Apr 2013 01:16 AM
May I have the output?
Report Abuse
Jackd44 is not online. Jackd44
Joined: 19 Dec 2008
Total Posts: 200
20 Apr 2013 01:22 AM
No output. Sorry.
Report Abuse
ball360 is not online. ball360
Joined: 31 Mar 2009
Total Posts: 1557
20 Apr 2013 01:27 AM
May I have the code you are currently working on?
Report Abuse
Jackd44 is not online. Jackd44
Joined: 19 Dec 2008
Total Posts: 200
20 Apr 2013 01:43 AM
It's the same as the one at the top, if you are too lazy to scroll up again, here is the code:

local BuyBrick = script.Parent

function onT(hit)
local m = Instance.new("Message")
local h = hit.Parent:FindFirstChild("Humanoid")
local Buyer = game.Players:playerFromCharacter(hit.Parent)
local NextIt = game.Workspace.ItNext
local buyName = game.Workspace:FindFirstChild("Be it next game - 30")
if h ~= nil then
if Buyer.leaderstats.Points.Value < 30 then
print("Not enough points")
--m.Parent = Buyer
--m.Text = "Sorry, you don't have enough points for this, you need 30!"
--wait(2)
--m:remove()
elseif NextIt.Value ~= "" then
print("Already bought")
--m.Parent = Buyer
--m.Text = "Sorry, somebody else has already bought this, try again next game"
--wait(2)
--m:remove()
else
Buyer.leaderstats.Points.Value = Buyer.leaderstats.Points.Value - 30
NextIt.Value = Buyer.Name
print("Successful!")
--m.Parent = hit.Parent
--m.Text = "Purchase successful! You'll be IT next game.(Refunds not included)"
--wait(2)
--m:remove()
wait(0.5)
end
end
end


BuyBrick.Touched:connect(onT)
Report Abuse
ball360 is not online. ball360
Joined: 31 Mar 2009
Total Posts: 1557
20 Apr 2013 01:48 AM
Oh, psh, I overlooked the code ;3;
Hm..I don't see any problems.....

NextIt.Value = Buyer.Character.Name

Try this..?
Report Abuse
Jackd44 is not online. Jackd44
Joined: 19 Dec 2008
Total Posts: 200
20 Apr 2013 02:00 AM
Ah, ok thanks. It does work, however I get a glitch in studio where the names of strings don't appear in the properties tab even though they're actually there. :/ Thanks for the help though! Appreciated :D
Report Abuse
ball360 is not online. ball360
Joined: 31 Mar 2009
Total Posts: 1557
20 Apr 2013 02:01 AM
Tally-ho~ ^^
Report Abuse
Jackd44 is not online. Jackd44
Joined: 19 Dec 2008
Total Posts: 200
20 Apr 2013 02:11 AM
Do you get this issue as well?
Report Abuse
ball360 is not online. ball360
Joined: 31 Mar 2009
Total Posts: 1557
20 Apr 2013 02:14 AM
Nope o3o
Studio is unpredictable.
Report Abuse
jingler6623 is not online. jingler6623
Joined: 02 Jan 2012
Total Posts: 7618
20 Apr 2013 02:29 AM
Can you help me to script?
Report Abuse
Jackd44 is not online. Jackd44
Joined: 19 Dec 2008
Total Posts: 200
20 Apr 2013 02:40 AM
Hey, I know of a secret place where one can learn to script. However before you enter this mysterious land you need to know some things. 1. Scripting requires you to invest ALOT of time into it. 2. It could be difficult depending on your age, I tried from when I was around 10 years old, now and only now at the age of 13 have I began to understand it thoroughly. 3. Post in this forum IF YOU HAVE MADE A SCRIPT AND HAVE A PROBLEM WITH IT, not if you want a script made. That is all, now if you are sure you can handle these things and are ready to travel through an age of scripting go here: http://wiki.roblox.com/index.php/Scripting now if you return here, you might need help with something else, now I'll tell you another good place with tutorials and things of the like(Well the wiki has tut's too.) Here is Lualearners, they do things with roblox LUA too. They have a roblox group found here: http://www.roblox.com/Groups/group.aspx?gid=96651 and an official website found here: http://www.lualearners.org/
TL;DR If you couldn't be bothered to read this, then your patience is far too small, if you couldn't read through this whole post, then you have small chances to learn to script. That is all, goodbye, and good luck with your scripting!
Report Abuse
ball360 is not online. ball360
Joined: 31 Mar 2009
Total Posts: 1557
20 Apr 2013 02:41 AM
I would love to, but I have my hands full right now ;U;
I encourage you to read up on Wiki articles and look at Free Models.
Report Abuse
Jackd44 is not online. Jackd44
Joined: 19 Dec 2008
Total Posts: 200
20 Apr 2013 02:43 AM
Oh, and the title is "Learn to script, jh" That should be "Good luck, and may the code be with you" :)
Report Abuse
Jackd44 is not online. Jackd44
Joined: 19 Dec 2008
Total Posts: 200
20 Apr 2013 04:59 AM
New error around. Now I'm trying to make it so a player has been chosen and their name is stored inside a variable named "NextIt"(Don't worry, I have set a path, it knows what NextIt is and where it is.) And soon through my script I get this error:Unable to cast value to Object
Script "Workspace.HideAndSeek", Line 130 - global Choose_It

Ok, so I gathered that it was around line 130, so I take a look there.
130-it = game.Players:playerFromCharacter(NextIt.Value)
131-m.Text = it.Name.." has been chosen! Because they bought the V.I.P room bonus!"
Now after lots of testing and messing around I couldn't understand what was going wrong. Does anyone know the answer?
Report Abuse
GuideHelper is not online. GuideHelper
Joined: 01 Jun 2011
Total Posts: 1712
20 Apr 2013 05:15 AM
:P May the codes ever be in your favor.

gυι∂єнєℓρєя
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