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

How can i Make an item drop out of a certain NPC?

Asked by
worklok -24
5 years ago
Edited 5 years ago

i am having trouble in here.

I tried to make it drop out of a NPC, but it works with all players.

the NPC I want the item to fall from's name is 'King Cake'(location:game.workspace)

the item I want it to make it drop from KingCake on death name is 'Chest1'(location:game.ReplicatedStorage)

my script appears to work on all players(it works in ROBLOX Studio, but not in the real game. Why?)

script info:

LocalScript(name:LocalScriptKC)(location:StarterGui)

my script:

local part = game.ReplicatedStorage.Chest1 --name of my thing
local plr = game.Players.LocalPlayer
local character = plr.Character
local humanoid = character.Humanoid

humanoid.Changed:connect(function()
 if humanoid.Health <= 0 then
  local clone = part:Clone()
  clone.Parent = workspace
  clone.Body.Position = character["Torso"].Position + 
         Vector3.new(math.random(-5, 5), 0, math.random(-5, 5))
  clone.Body.Rotation = Vector3.new(math.random(10, 100), 0, math.random(10, 100))
 end
end)

please help me. thanks

(sorry for bad grammar)

0
Is the game filtering enabled? ProjectJager 62 — 5y
0
no worklok -24 — 5y
0
did you use game:GetService("ReplicatedStorage") ProjectJager 62 — 5y
0
no, i used 'local part = game.ReplicatedStorage.Chest1 --this is the name of the item i want it to drop when kingcake npc dies. worklok -24 — 5y

1 answer

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

Hey,

Try using the Died Event like so

humanoid.Died:Connect(function()
    local clone = part:Clone()
    clone.Parent = workspace
    --and so on
end

EDIT********************

Here is how i would set this up.

Insert a script into the npc model.

script:

local humanoid = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso") -- this is assuming the npc model has a Torso

humanoid.Died:Connect(function()
    local clone = game.ReplicatedStorage.Chest1:Clone()
    clone.Parent = workspace
    clone.Body.Position = torso.Position + Vector3.new(math.random(-5,5), 0, math.random(-5,5))

end)

EDIT AGAIN ***************************

So if you want to move a model with multiple pieces what you need to do is:

click the model and set the Property called "PrimaryPart" as one of the parts of the model (Usually the biggest or most center part)

Then if you want to move the whole model you can do:

local model = game.ReplicatedStorage.Model -- random example
model:SetPrimaryPartCFrame(CFrame.new(0,0,0)) -- the 0's are numbers that you must choose.
0
but i want the chest to drop when a certain npc dies. how? worklok -24 — 5y
0
you can do the same thing if the npc has a humanoid in it PoePoeCannon 519 — 5y
0
i dont want it to drop when a player dies, i dont know where to put the name of my npc. please help. worklok -24 — 5y
0
try putting a script inside of the npc with this code in it. PoePoeCannon 519 — 5y
View all comments (32 more)
0
with the variables of course linking to its own humanoid and torso PoePoeCannon 519 — 5y
0
alright ill try it, thanks worklok -24 — 5y
0
let me know how it works! PoePoeCannon 519 — 5y
0
wait where do i put the (local)script? worklok -24 — 5y
0
doesnt work worklok -24 — 5y
0
You wont need a local script with this one. PoePoeCannon 519 — 5y
0
All you need to do is put a script inside of the npc and have a variable for the humanoid of that npc. When the humanoid of that npc dies, then the chest should spawn on the npc's torso. If you are getting errors pls tell me what they say. PoePoeCannon 519 — 5y
0
can you give me the whole script?because i am having trouble here. also, should i create a localscript or a script?i put a script inside the humanoid. worklok -24 — 5y
0
yea ill write another script for u real quick gimme a sec PoePoeCannon 519 — 5y
0
alright bro thanks worklok -24 — 5y
0
reply to clone.body question:according to the guide i read on my phone, it said 'clone' should clone the item. worklok -24 — 5y
0
well, we are cloning Chest1. Is Chest1 a model? or is it a single part. PoePoeCannon 519 — 5y
0
is Body the name of a part inside Chest1? PoePoeCannon 519 — 5y
0
the chest is just a model. worklok -24 — 5y
0
Okay, so it is a model with multiple parts to it correct? (I need to know because you have to move the position of a model a certain way) PoePoeCannon 519 — 5y
0
the model is just a part with a mesh, worklok -24 — 5y
0
okay sweet and the part is called Body right? PoePoeCannon 519 — 5y
0
okay i updated the script PoePoeCannon 519 — 5y
0
whoops, forgot to clone it. Now it is updated lol PoePoeCannon 519 — 5y
0
the model is a part with a mesh,2 scripts(the first one is on touch destroy, and the other one is a money giver) worklok -24 — 5y
0
the end is underlined, i think its invalid. worklok -24 — 5y
0
oh sorry, put a ) at the end PoePoeCannon 519 — 5y
0
still doesnt work worklok -24 — 5y
0
are you getting an error? PoePoeCannon 519 — 5y
0
Just tested it on my server and it worked fine PoePoeCannon 519 — 5y
0
the chests dont spawn :/ worklok -24 — 5y
0
What does the error say i mean PoePoeCannon 519 — 5y
0
wait!now it works! thank you dude! worklok -24 — 5y
0
1 more question, how can i make it so several parts sound? worklok -24 — 5y
0
spawn** worklok -24 — 5y
0
I'll write another edit onto the main post and tell you how, one sec. (Also, if i helped would you mind accepting the answer. ty!) PoePoeCannon 519 — 5y
0
thanks for answering! worklok -24 — 5y
Ad

Answer this question