|
| 10 May 2016 09:34 PM |
--Here is the problem:
--_______________________________________________________________________ script.Parent.Touched:connect(function() for _,Player in pairs(game.Players:GetPlayers()) do if Player:FindFirstChild("leaderstats") then Player.leaderstats.Hits.Value = Player.leaderstats.Hits.Value + Player.leaderstats.Level.Value game.Workspace.Serverhits.Value = game.Workspace.Serverhits.Value + Player.leaderstats.Level.Value end end end) --________________________________________________________________________ --This script is wonderful when there is only one player on the server. --But slow to realize, someone joined my game. --I hit the ball. --We both got a point.
print "BUT THATS NOT ALL"
--For some straaanngggeee reason, he got one point, and I got 6 points. --I was leaderstats.Level.Value = 6 --That's normal, right? --But why didn't the other guy get 6 points, if hitting the ball gives us both points?
--BTW the script is in the ball part in the workspace in the game. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 10 May 2016 09:39 PM |
because you made a loop to give everyone in the server a point when it's touched
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local Player = game.Players:GetPlayerFromCharacter(hit.Parent) if Player:FindFirstChild("leaderstats") then Player.leaderstats.Hits.Value = Player.leaderstats.Hits.Value + Player.leaderstats.Level.Value game.Workspace.Serverhits.Value = game.Workspace.Serverhits.Value + Player.leaderstats.Level.Value end end end)
Sorry for the lack of indentation |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 10 May 2016 09:40 PM |
d=false script.Parent.Touched:connect(function(hit) if d==false then d=true if game.Players:GetPlayerFromCharacter(hit.Parent) then plr=game.Players:GetPlayerFromCharacter(hit.Parent) plr.leaderstats.Hits.Value=plr.leaderstats.Hits.Value+1 wait(1) d=false end end end) |
|
|
| Report Abuse |
|
|
|
| 10 May 2016 09:42 PM |
This is because you loop through all players in the game, and you add their Level to their Hits stat.
His level was 1, so he got 1 point. Your level was 6, so you got 6 points.
Let's look here:
for _,Player in pairs(game.Players:GetPlayers()) do if Player:FindFirstChild("leaderstats") then Player.leaderstats.Hits.Value = Player.leaderstats.Hits.Value + Player.leaderstats.Level.Value game.Workspace.Serverhits.Value = game.Workspace.Serverhits.Value + Player.leaderstats.Level.Value end end
Assume 2 players in the game:
minerioProgramer AgentFirefox
This is the process of the loop:
for each player ... Player: minerioProgramer if minerioProgramer has leaderstats, then add minerioProgramer's level to his Hits stat end if
loop
Player: AgentFirefox if AgentFirefox has leaderstats, then add AgentFirefox's level to his Hits stat end if
loop
! No players left ! end for
So as you can see, your loop adds points to each player based on his own level. |
|
|
| Report Abuse |
|
|
|
| 10 May 2016 09:46 PM |
| Thank you guys, I didn't see that dumb mistake I made. |
|
|
| Report Abuse |
|
|