Hello! I am trying to make a script when the player dies it clones a certain part in the players position, but it doesn't see to clone. Can anyone help me please?
Here is my current script:
local character = script.Parent local humanoid = character:FindFirstChild("Humanoid") local player = game.Players:GetPlayerFromCharacter(character) local object = game.workspace.Food humanoid.Died:Connect(function() print("Humanoid Died") print(player.Character.Head.Position) local ClonedObject = object:Clone() ClonedObject.Parent = workspace ClonedObject.Name = ("Food") ClonedObject.Position = player.Character.Head.Position print("Cloned (Hopefully)") end)
(If your wondering about the game, Im making a hunger system where the player has to touch the part to eat.) I've thought about instancing the part but its not possible because there is a value inside of it and if many players die the script wouldn't know what part to put the value in.
Sorry if this is a dumb question, kinda new to scripting.
("Food")
is not the proper way to do quotes, try "Food"
, and if that's not the problem try doing ClonedObject:MoveTo(player.Character.Head.Position)
instead of ClonedObject.Position = player.Character.Head.Position
I've figured it out myself, Thanks for the help tho. Heres what I did:
local char = script.Parent local humanoid = char:FindFirstChild("Humanoid") local Food = game.Lighting.Food humanoid.Died:Connect(function() Food.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(math.random(-5, 5), 0, math.random(-5, 5)) Food:Clone().Parent = game.Workspace Food:Clone().CanCollide = false end)
I've revamped my code, The problem I found was that the player sometimes touched the part when they die, so it would get "eaten" even tho they're dead. Simple fix tho. Also I found that my hunger script was deleting it, so no wonder I couldn't see it. I tried moving the part to "Lighting" and it works fine.
Thanks everyone for the help.