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

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

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)

2 comments

0

Local.

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.

2 answers

✓ Accepted answer

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

3 comments

0

I did some research on how to find the player who killed the NPC and found that ROBLOX has disabled this function.

0

I want all players to get the XP, because they're all working together in the dungeon.

0

Oh, ok. I'll fix up the script for you. I thought this was a solo thing,

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

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