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

Does anyone know why my script that gives EXP on kill to all players wont work?

local EXP = script.Parent.Parent.EXP
local Gold = script.Parent.Parent.Gold
local ZP1 = game.Workspace.ZP1

while true do
	wait(0.1)
	if ZP1.CanCollide == true then
		EXP.Value = EXP.Value + 1
		Gold.Value = Gold.Value + 1
		wait(0.2)
		game.Workspace.ZP1.CanCollide = false
	else
		print("No EXP given.")
	end
end

In the game, when the zombie is killed, it turns on CanCollide, which is supposed to trigger this script. However, it doesn't add the EXP or gold, even when CanCollide is on. Can someone help me with this? (btw it gives the exp to everyone)

6 comments

0

does it print no EXP given or nothing?

0

nope

0

if it doesn't print no EXP given then I can't see how it could not be doing the if statement since it's in a while loop. Try putting a print in the if statement?

0

is ZP1 a part

0

Yes.

0

Wait, the script wont run

1 answer

✓ Accepted answer

I was able to fix this, by making a script inside the Zombie. Here it is.

local zombie = script.Parent
local Humanoid = zombie:WaitForChild("Zombie")

Humanoid.Died:Connect(function()
	for i,Player in pairs(game.Players:GetPlayers()) do
		Player.leaderstats.EXP.Value = Player.leaderstats.EXP.Value + 1
		Player.leaderstats.Gold.Value = Player.leaderstats.Gold.Value + 1
		print("Exp awarded")
	end
	wait(2)
	zombie:Destroy()
end)

1 comment

0

glad u got it working girl :D

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