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

currency system, im making it so that you kill a zombie and it give u money pls help script no work?

game.Players.PlayerAdded:Connect(leaderboardSetup)
game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player
	
	local cash = Instance.new("NumberValue")
	cash.Name = "Cash"
	cash.Value = 0
	cash.Parent = leaderstats
	
	player.CharacterAdded:Connect(function(Character)
		Character.Humanoid.Died:Connect(function(Died)
			local creator = Character.Humanoid:FindFirstChild("creator")
			local leaderstats = creator.Value:FindFirstChild("leaderstats")
			if creator ~= nil and creator.Value ~= nil then
				leaderstats.Cash.Value = leaderstats.Cash.Value + 10
			end
		end)
	end)
end)
	
	
	
	
	
	
	
	
	
	
end)

idk y if u know pls type why and the fixed script ill accept the answer if its correct i check every hour

4 comments

0

is this script inside of the zombie?

0

what does leaderboardSetup do?

0

Script is in serverscriptservice

0

with your current script, you're checking when the player dies

1 answer

✓ Accepted answer

In this script, you are looking for a child of a value, which wont exist. Use bindableevents to fire between scripts

--Script in the tool (add this in with the gun, Hit = raycast.Instance or whatever you use
local Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) or script.Parent.Parent.Parent

local Tagged = Instance.new("ObjectValue")
Tagged.Name = "creator"
Tagged.Value = Player
Tagged.Parent = Hit.Parent.Humanoid
game.Debris:AddItem(Tagged, 2)

--Script inside the zombie
local Character = script.Parent
Character.Humanoid.Died:Connect(function()
	if Character.Humanoid:FindFirstChild("creator") then
		local Player = Character.Humanoid.creator.Value
                local Leaderstats = Player.leaderstats
                Leaderstats.Cash.Value += 10
            end
end

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