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)
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)