Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Part not cloning in players position?

Asked by
WH_HAN 2
4 years ago
Edited 4 years ago

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.

0
Anchor the part. greatneil80 2647 — 4y
0
It is. WH_HAN 2 — 4y
0
is it a model? greatneil80 2647 — 4y
0
nevermind just noticed the comment on the other guys's answer.. also ("Food") looks ugly, try just "Food" greatneil80 2647 — 4y
View all comments (2 more)
0
Im not sure if this will work but instead of having the ClonedObject.Parent be the workspace, make it the model in which the body parts of the player are in. So that would be local character probably. xWolfXtreme 2 — 4y
0
Something else you did wrong was the fact that you did the local for the clone but never actually did "object:Clone() xWolfXtreme 2 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

("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

0
It did clone, Just not in the right place. WH_HAN 2 — 4y
0
do ClonedObject:MoveTo(player.Character.Head.Position) instead of ClonedObject.Position = player.Character.Head.Position DbExpress 20 — 4y
0
"MoveTo is not a valid member of Part" WH_HAN 2 — 4y
0
Are you using MoveTo on a part or model? CreationNation1 459 — 4y
Ad
Log in to vote
0
Answered by
WH_HAN 2
4 years ago

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.

0
(I forgot to say how I fixed the "accidental eating" I basically just made it so that the part flings away from the player "Vector3.new(math.random(-5, 5), 0, math.random(-5, 5))") WH_HAN 2 — 4y

Answer this question