Zerio920
|
  |
| Joined: 06 Apr 2012 |
| Total Posts: 3311 |
|
|
| 15 Feb 2014 08:54 PM |
I have this script:
function touch(hit) for _,Player in pairs(game.Players:GetPlayers()) do if Player:FindFirstChild("leaderstats") then Player.leaderstats.Expines.Value = Player.leaderstats.Expines.Value +1 else end end end script.Parent.Touched:connect(touch)
I put this script in a brick, which is supposed to give you one extra point, called "expines" in the game, whenever you touch it. It's also supposed to kill you when you touch it. The problem is, when you touch the brick, you die, but you keep getting points since youre still touching the brick even though you're dead. So how do I fix this so the script only works when youre alive? |
|
|
| Report Abuse |
|
|
|
| 15 Feb 2014 08:59 PM |
Your script currently gives *everyone* 1 point. Try this instead:
function touch(hit) if (hit and hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid.Health > 0) then local expines = game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.expines expines.Value = expines.Value + 1 hit.Parent:BreakJoints() end end
script.Parent.Touched:connect(touch)
Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 15 Feb 2014 09:00 PM |
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humnaoid") ~= nil then if hit.Parent.Health >= 0 then return else for i,v in pairs(game.Players:GetPlayers()) do if v:FindFirstChild("leaderstats") then v.leaderstats.Expines.Value = Player.leaderstats.Expines.Value + 1 end end end end) |
|
|
| Report Abuse |
|
|
Zerio920
|
  |
| Joined: 06 Apr 2012 |
| Total Posts: 3311 |
|
|
| 15 Feb 2014 09:32 PM |
| @DaMrNelson : Now it's not giving me any points by touching it. .-. |
|
|
| Report Abuse |
|
|
|
| 15 Feb 2014 09:35 PM |
@Zerio Da made one tiny error. I hope you can see what it is.
game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Expines.Value |
|
|
| Report Abuse |
|
|
Zerio920
|
  |
| Joined: 06 Apr 2012 |
| Total Posts: 3311 |
|
|
| 15 Feb 2014 09:37 PM |
| @Goulstem doesnt work either .-. |
|
|
| Report Abuse |
|
|
Zerio920
|
  |
| Joined: 06 Apr 2012 |
| Total Posts: 3311 |
|
|
| 15 Feb 2014 09:38 PM |
| @Voidshredder : Who are you .-. and whats the full script? |
|
|
| Report Abuse |
|
|
|
| 15 Feb 2014 09:41 PM |
I am VoidShredder thank you very much
function touch(hit) if (hit and hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) and hit.Parent.Humanoid.Health > 0) then local expines = game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Expines--See this was where he forgot a CAPS error. Such a minor error that was obvious with output expines.Value = expines.Value + 1 hit.Parent:BreakJoints() end end
script.Parent.Touched:connect(touch) |
|
|
| Report Abuse |
|
|
Zerio920
|
  |
| Joined: 06 Apr 2012 |
| Total Posts: 3311 |
|
|
| 15 Feb 2014 09:50 PM |
| Ohh I see. It kinda works now, but it still seems to be doing that thing where it still gives you a point even if youre dead. |
|
|
| Report Abuse |
|
|
|
| 15 Feb 2014 09:51 PM |
debounce then
local debounce = false function touch(hit) if (hit and hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) and hit.Parent.Humanoid.Health > 0) then if debounce then return end debounce = true local expines = game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Expines--See this was where he forgot a CAPS error. Such a minor error that was obvious with output expines.Value = expines.Value + 1 hit.Parent:BreakJoints() wait(.1) debounce = false end end |
|
|
| Report Abuse |
|
|
|
| 15 Feb 2014 09:55 PM |
Wait (.1)? Itll do pretty much same thing.. wait (2) would be better |
|
|
| Report Abuse |
|
|
Zerio920
|
  |
| Joined: 06 Apr 2012 |
| Total Posts: 3311 |
|
|
| 15 Feb 2014 10:03 PM |
@voidshredder : Now it's not working at all .-.
Am I supposed to copy the "debounce then" or do I just leave it, cause I left that part out. |
|
|
| Report Abuse |
|
|
|
| 15 Feb 2014 10:07 PM |
script.Parent.Touched:connect(touch)
This line needs to be at the very end again. |
|
|
| Report Abuse |
|
|
Zerio920
|
  |
| Joined: 06 Apr 2012 |
| Total Posts: 3311 |
|
|
| 15 Feb 2014 10:47 PM |
| Ok, how do I change the script so I can put it in a brick that doesn't kill you, but it only works once, so once you touch it you can't get the points again, even if you reset? |
|
|
| Report Abuse |
|
|
iIikeyou
|
  |
| Joined: 07 Mar 2012 |
| Total Posts: 1659 |
|
|
| 15 Feb 2014 10:54 PM |
local t={} script.Parent.Touched:connect(function(c) local p=game.Players:GetPlayerFromCharacter(c.Parent) if p and not t[p]then t[p]=true local e=p.leaderstats.Expines e.Value=e.Value+1 --c.Parent:BreakJoints() --remove the dashes on the line above for it to kill end end) |
|
|
| Report Abuse |
|
|
SFOH
|
  |
| Joined: 01 Nov 2009 |
| Total Posts: 293 |
|
| |
|
7y13rb
|
  |
| Joined: 28 May 2011 |
| Total Posts: 223 |
|
|
| 15 Feb 2014 11:26 PM |
function touch(hit) if (hit and hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) and hit.Parent.Humanoid.Health > 0) then local expines = game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Expines--See this was where he forgot a CAPS error. Such a minor error that was obvious with output expines.Value = expines.Value + 1 hit.Parent:BreakJoints() end end
script.Parent.Touched:connect(touch) wait(10) --will just 10 seconds and you should regen and your body wont be there(dead or alive by this point)to get points. to do it without killing you just insert a number value into everyone's characters and dont let it get it if the numbervalue is over 1 and use this:
function touch(hit) local player = game.Players.findFirstChild(hit.Parent.Name) local collected = player.findFirstChild("Collect") if collected = 0 and (hit and hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then local expines = game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Expines--See this was where he forgot a CAPS error. Such a minor error that was obvious with output expines.Value = expines.Value + 1 collected = 1 end end end
and put this into Workspace: function onPlayerEntered(newPlayer) wait(.5) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local stats2 = Instance.new("IntValue") stats2.Name = "Collect"
stats2.Parent = newPlayer stats.Parent = newPlayer
end
game.Players.ChildAdded:connect(onPlayerEntered)
or something like that...good luck :D (this might not work i'm half asleep lol..) |
|
|
| Report Abuse |
|
|
7y13rb
|
  |
| Joined: 28 May 2011 |
| Total Posts: 223 |
|
|
| 15 Feb 2014 11:28 PM |
| yeah i did copy the script from someone earlier and edit slightly...as i said i was half asleep. i made the other script though. good luck again |
|
|
| Report Abuse |
|
|