Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Bman8765 270 Moderation Voter
9 years ago

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)
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. BlueTaslem 18071 — 9y
0
Okay Bman8765 270 — 9y

1 answer

Log in to vote
0
Answered by
Bman8765 270 Moderation Voter
9 years ago

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

Answer this question