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

Why is the variables getting confused, is there a mistake in the script?

Something is wrong with this script bc when I die the money is given and not when the zombie dies. It is a 1 player game. This is a local script

local player = game.Players
local zombie = script.Parent.Zombie

if zombie.health >=("0")
then player.RealMoney.Value = player.RealMoney.Value + 10
else player.RealMoney.Value = player.RealMoney.Value + 0

end

1 comment

1 answer

✓ Accepted answer
--[[Died version-
This works as well, even better actually, but I just tried to give you a solution based on your format. I just correct your mistakes
]]

local player = game.Players -- If the script doesn't work put game.Players["PLAYERNAME"]
local zombie = script.Parent.Zombie
local db = false

zombie.Humanoid:Died:connect(function()
if (db == false) then
	db = true
	player.RealMoney.Value = player.RealMoney.Value + 10
	db = false
	end
end)
--try this
--This will only run once

local player = game.Players -- This has to be defined furthermore
local zombie = script.Parent.Zombie

if zombie.Humanoid.Health <= ("0") then -- you had > instead of < 
player.RealMoney.Value = player.RealMoney.Value + 10
end

4 comments

0

Humanoid.Died is much better.

0

ok

0

Thx for the edit

0

Np. Jesse recommended it!

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