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

Why does this script not change the value of the players EXP?

Asked by 4 years ago
Edited 4 years ago
local Player = game.Players.LocalPlayer
local Stats = Player:WaitForChild("leaderstats")
local Figure = script.Parent
local Humanoid = Figure:WaitForChild("Humanoid")
local EXP = Stats:WaitForChild("EXP")

while Humanoid.Health < 1 do
    EXP.Value == EXP.Value + 1
    Figure:Destroy()
end

I wanna have this make it so when the zombie dies, it gives the player EXP, I can't figure out what is wrong with this script, and it showsup as an error in line 8, under EXP.Value. Does anyone know why? (This is a LocalScript)

0
Local. Trisodin529 89 — 4y
0
Since you're doing this in a LocalScript, it only happens on the Client Side, not the Server Side. Try using RemoteEvents and a ServerScript and a LocalScript. killerbrenden 1537 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

To do this, you will need a ServerScript inside of the NPC that will die.

To start off, you would want to check if the NPC died and then increase everyone's exp by a certain amount that you would like.

ServerScript inside of the NPC

local hum = script.Parent:WaitForChild("Humanoid")

hum.Died:Connect(function()
    local EXP_AMOUNT = 100 --// Change this to the amount of EXP you want them to receive
    for _,player in pairs(game:GetService("Players"):GetPlayers()) do
        local exp = player:WaitForChild("leaderstats"):FindFirstChild("EXP")
        exp.Value = exp.Value + EXP_AMOUNT
    end
end)

This is a ServerScript so it will server cross, if this was in a LocalScript it would only happen on the client side, not the server side. So, the EXP wouldn't save in the data save.

Hope this helped! If it worked, let me know by selecting this as the answer, if it didn't comment down below what went wrong and how I can help.

~killerbrenden

0
I did some research on how to find the player who killed the NPC and found that ROBLOX has disabled this function. killerbrenden 1537 — 4y
0
I want all players to get the XP, because they're all working together in the dungeon. Trisodin529 89 — 4y
0
Oh, ok. I'll fix up the script for you. I thought this was a solo thing, killerbrenden 1537 — 4y
Ad
Log in to vote
0
Answered by
haba_nero 386 Moderation Voter
4 years ago

I can help you with this in person. Shoot me a request and I will accept it @TheLastHabanero. This is hard to explain in writing so I will help you with your game personally.

Best

-TheLastHabanero

Answer this question