I am currently making an NPC for a tycoon I’m working on, but I can’t find a way to script the reward when said NPC has been killed. I get an error saying "Expected ‘)’ (to close ‘(’ at line 12), got <eof’> "
Can anyone help?
Code:
function tagHumanoid(humanoid, player)
local tag = Instance.new("ObjectValue")
tag.Value = player
tag.Name = "creator"
tag.Parent = script.Parent.Humanoid
game:GetService("Debris"):AddItem(tag,.5)
deb = false
humanoid.Died:connect(function()
local tag = humanoid:FindFirstChild(“creator”)
if tag then
local plr = tag.Value
if deb == false then
deb = true
local plr = game.ServerStorage.PlayerMoney:FindFirstChild(player.Parent.Name)
plr.Value = plr.Value + script.Parent.Parent.Amount.Value
wait(script.Parent.Parent.TimeToWait.Value)
deb = false
end
end
end
Something is obviously wrong here, but I can’t figure out what / why
You forgot a ) on one of your ends
You forgot to implement a couple ends in your script
function tagHumanoid(humanoid, player)
local tag = Instance.new("ObjectValue")
tag.Value = player
tag.Name = "creator"
tag.Parent = script.Parent.Humanoid
game:GetService("Debris"):AddItem(tag,.5)
deb = false
end
humanoid.Died:Connect(function()
local tag = humanoid:FindFirstChild("creator")
if tag then
local plr = tag.Value
if deb == false then
deb = true
local plr = game.ServerStorage.PlayerMoney:FindFirstChild(player.Parent.Name)
plr.Value = plr.Value + script.Parent.Parent.Amount.Value
wait(script.Parent.Parent.TimeToWait.Value)
deb = false
end
end
end)
No, that is the line that reads humanoid.Died:connect(function(), I included all )
now it says that both “humanoids” and “player” are unknown globals
Because it doesn’t know what humanoid is — The OnDied function doesnt recognize a variable named humanoid
You should reference the humanoid inside a CharacterAdded Event instead, and fire that tagHumanoid function in a separate tool script where it’ll tag the Humanoid but ok
function tagHumanoid(humanoid, player)
local tag = Instance.new("ObjectValue")
tag.Value = player
tag.Name = "creator"
tag.Parent = script.Parent.Humanoid
game:GetService("Debris"):AddItem(tag,.5)
deb = false
humanoid.Died:Connect(function()
local tag = humanoid:FindFirstChild("creator")
if tag then
local plr = tag.Value
if deb == false then
deb = true
local plr = game.ServerStorage.PlayerMoney:FindFirstChild(player.Parent.Name)
plr.Value = plr.Value + script.Parent.Parent.Amount.Value
wait(script.Parent.Parent.TimeToWait.Value)
deb = false
end
end
end)
end