Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script Broke, Any help?

I have this script, and the line it breaks on is "player.leaderstats.points.Name = player.leaderstats.Credits + 200" The reason is the stats on the leader are points but are named under Credits.

This is the script:

game.Workspace.ChildAdded:connect(function(child) 

if child.Name == "HostageFree" then 
script.Sound:Play()--Don't worry about here and above

for _,player in pairs(game.Players:GetPlayers()) do  
if player.TeamColor == BrickColor.Red() then  
player.leaderstats.points.Name = player.leaderstats.Credits + 200 --Broken line

wait(7) --Don't worry about here and below
local pl = game.Players:GetChildren()
for i=1,#pl do
pl[i].Character.Humanoid.Health = 0
game.Workspace.HostageFree:Remove()
end
end 
end
end 
end) 

NOTICE: the leaderboard stat is points but I named them Credits so when it appears on players leaderboard ingame it appears as Credits but still is referred to as points in script. But you have to add +200 to Credits

2 answers

✓ Accepted answer
game.Workspace.ChildAdded:connect(function(child) 

if child.Name == "HostageFree" then 
script.Sound:Play()--Don't worry about here and above

for _,player in pairs(game.Players:GetPlayers()) do  
if player.TeamColor == BrickColor.Red() then  
player.leaderstats.Credits.Value = player.leaderstats.Credits.Value + 200 --Broken line

wait(7) --Don't worry about here and below
local pl = game.Players:GetChildren()
for i=1,#pl do
pl[i]:LoadCharacter() -- This is a faster way of resetting them. If you've ever used an admin script, this would be the equivalent of :Respawn [person]
game.Workspace.HostageFree:Destroy() -- use destroy whenever possible.
end
end 
end
end 
end) 

7 comments

0

I use the kill function to change player team colors and to remove their weapons

0

Okay, well you can replace it if you want..

0

No its fine, but the script part where giving the players the points didnt work

0

Changed it.

0

I tried that too ealier myself, didnt work, read my updated notice

0

Now try.

0

i fixed it myself take a look below.

Fixed it myself :p

game.Workspace.ChildAdded:connect(function(child) 

if child.Name == "HostageFree" then 
script.Sound:Play()

for _,player in pairs(game.Players:GetPlayers()) do  
if player.TeamColor == BrickColor.Red() then 
local leaderstats = player.leaderstats
local points = leaderstats:findFirstChild("Credits") 
points.Value  = points.Value +200

wait(7)
local pl = game.Players:GetChildren()
for i=1,#pl do
pl[i].Character.Humanoid.Health = 0
game.Workspace.HostageFree:Remove()
end
end 
end
end 
end) 

2 comments

0

Sorry about the broken script, I didn't understand you on the points/credits part.

0

its ok

This discussion is preserved as it was. New answers, comments, and votes are closed.