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

Killing an npc gives you a reward issue? [Solved]

So basically I have a zombie npc and every time you kill the zombie it should give the last player that damaged it a reward, the problem is it's not doing this and I really don't have a solution. Maybe one of you guys can figure it out?

rewardmessage = game.Lighting.KillerReward

script.Parent.Zombie.Died:connect(function()
	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
	end
end)

2 comments

0

If you figured it out, feel free to post an answer explaining what you had to do. It could help other people who have similar issues, or who just can't figure out what's wrong here.

0

Okay

1 answer

BlueTaslem helped me but here is a simple solution to those needing help. I was trying to use a objectvalue to find a location in Players but this requires a string value and objectvalue is not a string value. To fix this all you need to do is to get the name of the value of the objectvalue... Example: objectvalue.Value.Name and then I can use this as the location!

Here is the fixed code:

rewardmessage = game.Lighting.KillerReward

script.Parent.Zombie.Died:connect(function()
	if script.Parent.Zombie.Health == 0 then
		local killer = script.Parent.Zombie.creator
		print(killer.Value.Name)
		local rewardclone = rewardmessage:clone()
		rewardclone.Parent = game.Players[killer.Value.Name].PlayerGui.MainScreen
		if game.Players[killer.Value.Name].PlayerGui.MainScreen.PlayerValues.HasCoinBooster.Value == true then
			rewardclone.CoinReward.Text = "+2 coins"
			if game.Players[killer.Value.Name].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.Name].PlayerGui.MainScreen.PlayerValues.HasXPBooster.Value == true then
				rewardclone.XPReward.Text = "+10 XP"
			else 
				rewardclone.XPReward.Text = "+5 XP"
			end
		end
	end
end)

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