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

Money giving script doesnt work. How can i solve it ? It is a sword game

I made a sword game and i made a function which is giving money to winner. But it doesnt work

local mapstoragechild = game.Workspace.MapStorage:GetChildren()
local players = game.Players:GetPlayers()
local message = game.Workspace.Message
local rp = game.Workspace.MapStorage.Map.PlayerStorage:GetChildren()
function tpbak()
	for i = 1,#rp do
		rp[i].Humanoid.Health = 0
	end
end
while #mapstoragechild == 1 do
	local playerleft = game.Workspace.MapStorage.Map.PlayerStorage:GetChildren()
	function gibmw()
		local plp = playerleft:GetPlayerFromCharacter()
		for i = 1, #playerleft do
			plp[i].leaderstats.Money.Value = plp[i].leaderstats.Money.Value + 10 
		end
	end
	if #playerleft == 1 then
		gibmw()
		tpbak()
		wait(2)
		game.Workspace.MapStorage:ClearAllChildren()
		script.Parent.Gameselect.Disabled = true
		wait(3)
		script.Parent.Intermission.Disabled = false
		game.Workspace.Gamemode.Value = 0
		message.Value = "Game Ended !"
		game.Workspace.Songs.Songloop.Disabled = false
		wait(1)
		script.Parent.Gameselect.Disabled = false
		script.Disabled = true
		break
	end
	wait(0.1)
end
--This script making 1 player left then shut the gametime and tp players and gib rewards

4 comments

0

have you put it in a script or a local script?

0

You have to show the entire script since you didn't show what is the value of "playerleft".

0

ok

0

your script confuses me

2 answers

I helped solving and we dont really know what was wrong because i just did an in pairs function to loop throught the remaining players and it worked!

i would change line 14 - 17 to:

for index, player in pairs(players) do
	player.leaderstats.Money.Value = player.leaderstats.Money.Value + 10
	end
end

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