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

Reward a player for killing a zombie?[UNSOLVED]

I have a script that rewards a player for killing a zombie but I'm having some issues with it, maybe one of you guys can help me fix the problem? Whenever the user kills a zombie this error outputs: Workspace.map1.Zombie.Reward:10: bad argument #2 to '?' (string expected, got userdata)

rewardmessage is a gui found in lighting everything else should be understandable oh also this script in found inside a zombie (npc, whatever you want to call it) (The script also is not fully completed, the main functional parts are coded but don't seem to be working) Script:

rewardednowdie = false
rewardmessage = game.Lighting.KillerReward

repeat
	wait()
	if script.Parent.Zombie.Health == 0 then
		local killer = script.Parent.Zombie.creator
		print(killer.Value)
		local rewardclone = rewardmessage:clone()
		rewardclone.Parent = game.Players[killer.Value].PlayerGui.MainScreen
		if game.Players[killer.Value].PlayerGui.MainScreen.PlayerValues.HasCoinBooster.Value == true then
			rewardclone.CoinReward.Text = "+2 coins"
			if game.Players[killer.Value].PlayerGui.MainScreen.PlayerValues.HasXPBooster.Value == true then
				rewardclone.XPReward.Text = "+10 XP"
			else rewardclone.XPReward.Text = "+5 XP"
			end
		else
			rewardclone.CoinReward.Text = "+1 coin"
			if game.Players[killer.Value].PlayerGui.MainScreen.PlayerValues.HasXPBooster.Value == true then
				rewardclone.XPReward.Text = "+10 XP"
			else 
				rewardclone.XPReward.Text = "+5 XP"
			end
		end
		rewardednowdie = true
	end
until rewardednowdie == true

1 answer

Well, instead of using a loop, you should use the died() event of humanoids; this will reduce lag.

script.Parent.Zombie.Died:connect(function()
--stuff goes here
end)

And a tagged humanoid will return the player instance, not just the name.

1 comment

0

Thanks for pointing this out but this still does not solve my problem..

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