|
| 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
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 24 Feb 2015 10:39 AM |
| You never defined player, so it's nil. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 24 Feb 2015 10:47 AM |
| This is just in script not local script. |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| Joined: 10 Jul 2008 |
| Total Posts: 1700 |
|
|
| 24 Feb 2015 11:05 AM |
| Add a ) onto the end of it then... xD |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 24 Feb 2015 11:42 AM |
| http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 24 Feb 2015 11:45 AM |
Thank you Seranok
Thank you to every one else that helped me also. |
|
|
| Report Abuse |
|
|