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 » Scripters
Home Search
 

Re: What am i doing wrong here (Stringvalue)

Previous Thread :: Next Thread 
ReverseUniverse is not online. ReverseUniverse
Joined: 23 Jan 2015
Total Posts: 1118
24 Feb 2015 10:38 AM
script.Parent.Touched:connect(function(hit)
humanoid = hit.Parent:FindFirstChild("Humanoid")
local StringValue = Instance.new("StringValue", player)
StringValue.Name = "Alive"

end


--Trying to give the humanoid a StringValue when the humanoid touches the part.
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
24 Feb 2015 10:39 AM
You never defined player, so it's nil.
Report Abuse
ReverseUniverse is not online. ReverseUniverse
Joined: 23 Jan 2015
Total Posts: 1118
24 Feb 2015 10:46 AM
script.Parent.Touched:connect(function(hit)
player = game.Players.Player
humanoid = hit.Parent:FindFirstChild("Humanoid")
local StringValue = Instance.new("StringValue", player)
StringValue.Name = "Alive"

end


I tried this but it did not work.

I would have to describe player as being local some how.
Report Abuse
ReverseUniverse is not online. ReverseUniverse
Joined: 23 Jan 2015
Total Posts: 1118
24 Feb 2015 10:47 AM
This is just in script not local script.
Report Abuse
compy111 is not online. compy111
Joined: 02 Apr 2009
Total Posts: 583
24 Feb 2015 10:49 AM
script.Parent.Touched:connect(function(hit)
humanoid = hit.Parent:FindFirstChild("Humanoid")
player = game.Players:FindFirstChild(hit.Parent.Name)
if player then
local StringValue = Instance.new("StringValue", player)
StringValue.Name = "Alive"
end
end

Since the value name is alive I think you better could use a BoolValue in this situation. It chooses true or false.
Report Abuse
ReverseUniverse is not online. ReverseUniverse
Joined: 23 Jan 2015
Total Posts: 1118
24 Feb 2015 10:53 AM
Co your script gave me this error:

Workspace.PointsGiver.Script:10: ')' expected (to close '(' at line 1) near
Report Abuse
ReverseUniverse is not online. ReverseUniverse
Joined: 23 Jan 2015
Total Posts: 1118
24 Feb 2015 11:04 AM
bump-1


Or if any one can suggest to me a better code to insert string value into Player.
Report Abuse
SLY3 is not online. SLY3
Joined: 10 Jul 2008
Total Posts: 1700
24 Feb 2015 11:05 AM
Add a ) onto the end of it then... xD
Report Abuse
ReverseUniverse is not online. ReverseUniverse
Joined: 23 Jan 2015
Total Posts: 1118
24 Feb 2015 11:21 AM
It works!

btw i did add a ) to the end but it gave me another error tried it again for some reason it works now.

Now i need to add a check some where in it to see if the player already has the string value in it, and if it does not to give the string value again.
Report Abuse
ReverseUniverse is not online. ReverseUniverse
Joined: 23 Jan 2015
Total Posts: 1118
24 Feb 2015 11:30 AM
What am i doung wrong here?


script.Parent.Touched:connect(function(hit)
if player:FindFirstChild("Number1") then
end
humanoid = hit.Parent:FindFirstChild("Humanoid")
player = game.Players:FindFirstChild(hit.Parent.Name)
if player then
local StringValue = Instance.new("StringValue", player)
StringValue.Name = "Alive"
end
end)
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
24 Feb 2015 11:32 AM
You need to learn to debug your own scripts. Put some print statements in your code like so:

player = game.Players:FindFirstChild(hit.Parent.Name)
print('player:', player)
if player then
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
24 Feb 2015 11:33 AM
"What am i doung wrong here?


script.Parent.Touched:connect(function(hit)
if player:FindFirstChild("Number1") then
end
humanoid = hit.Parent:FindFirstChild("Humanoid")
player = game.Players:FindFirstChild(hit.Parent.Name)
if player then
local StringValue = Instance.new("StringValue", player)
StringValue.Name = "Alive"
end
end)"

on the second line of your script, you tried to use player when it wasn't defined yet. move that if statement under where you defined player
Report Abuse
ReverseUniverse is not online. ReverseUniverse
Joined: 23 Jan 2015
Total Posts: 1118
24 Feb 2015 11:35 AM
I would really like to be able to debug my own code.

I don't enjoy going to forums every day asking for help.
Report Abuse
ReverseUniverse is not online. ReverseUniverse
Joined: 23 Jan 2015
Total Posts: 1118
24 Feb 2015 11:35 AM
*doing

sorry
Report Abuse
ReverseUniverse is not online. ReverseUniverse
Joined: 23 Jan 2015
Total Posts: 1118
24 Feb 2015 11:40 AM
script.Parent.Touched:connect(function(hit)

humanoid = hit.Parent:FindFirstChild("Humanoid")
player = game.Players:FindFirstChild(hit.Parent.Name)
if player:FindFirstChild("Alive") then
end
if player then
local StringValue = Instance.new("StringValue", player)
StringValue.Name = "Alive"
end
end)


I tried this but script still gives player more string values without ending.

When it sees the player already has a string value.
Report Abuse
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
24 Feb 2015 11:42 AM
http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
24 Feb 2015 11:42 AM
if [condition] then
end

Doesn't stop the function from executing. You need to add a return statement.

if [condition] then
return
end
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
24 Feb 2015 11:44 AM
script.Parent.Touched:connect(function(hit)

humanoid = hit.Parent:FindFirstChild("Humanoid")
player = game.Players:FindFirstChild(hit.Parent.Name)
if player:FindFirstChild("Alive") then
return
end
if player then
local StringValue = Instance.new("StringValue", player)
StringValue.Name = "Alive"
end
end)

i think that would work, or this might too

script.Parent.Touched:connect(function(hit)
humanoid = hit.Parent:FindFirstChild("Humanoid")
player = game.Players:FindFirstChild(hit.Parent.Name)
if player and not player:FindFirstChild("Alive") then
local StringValue = Instance.new("StringValue", player)
StringValue.Name = "Alive"
end
end)
Report Abuse
ReverseUniverse is not online. ReverseUniverse
Joined: 23 Jan 2015
Total Posts: 1118
24 Feb 2015 11:45 AM
Thank you Seranok

Thank you to every one else that helped me also.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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