Hello guys im here again and now the problem is easy but i tried all i can but its not enough
im making a detector and the problem is the script cant detect if its player or ai if player is work properly but on AI its not and get error
heres the code
local human = script.Parent:FindFirstChild("Humanoid")
local DiedExp = game.ReplicatedStorage:WaitForChild("DiedExp")
local char = script.Parent
human.Died:Connect(function()
local creator = human:FindFirstChild("creator")
local killer = creator.Value
local exp = killer.Stats.Exp
local player = game.Players:GetPlayerFromCharacter(creator.Value)
if killer and player then
DiedExp:FireServer(exp)
elseif not player then
print("Its not player")
end
end)
A way to detect it is by putting a string value in the players char and calling it team Then having the value as player and for the other Bot have the team value as Bot. Then detect the value and pit an if statement to judge whether to give xp or not
Just add a simple check to see if the “creator” tag exists.
local human = script.Parent:FindFirstChild("Humanoid")
local DiedExp = game.ReplicatedStorage:WaitForChild("DiedExp")
local char = script.Parent
human.Died:Connect(function()
local creator = human:FindFirstChild("creator")
if creator then
local killer = creator.Value
local exp = killer.Stats.Exp
local player = game.Players:GetPlayerFromCharacter(creator.Value)
if killer and player then
DiedExp:FireServer(exp)
elseif not player then
print("Its not player")
end
end
end)
I know this is over now but the post I made as just really dumb
Sorry if u confused ya
I just had a problem like this and realised
“OH object values exist”