I'm creating a humanoid that when it gets killed, it drops a dollar bill from the sky... The only thing is, I want the dollar to kill the humanoid when it collects it. This is what I have so far.
function onDied() for i =1,script.GoldCount.Value do local xp = Instance.new("Part") xp.Parent = game.Workspace xp.Position = script.Parent.Parent.Torso.Position + Vector3.new(math.random(-3,3),math.random(-3,3),math.random(-3,3)) xp.Shape = 1 xp.formFactor = "Symmetric" xp.Name = "XP" xp.BrickColor = BrickColor.new(1021) xp.Reflectance = 0.2 xp.Size = Vector3.new(1.5,.5,3) xp.TopSurface = 2 local clone = script.Increase:Clone() clone.Disabled = false clone.Parent = xp end end script.Parent.Died:connect(onDied)
Then I have a lava script that I was trying to put in the other, but didn't know how.
function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h ~= nil then h.Health = 0 end end script.Parent.Touched:connect(onTouched)
Anyone know how this could be fixed? Thanks!
Since the script is in the Humanoid, it will be deleted when the character respawns and any connections made by it will be broken, so creating the connection from the first script won't work.
I would recommend doing everything from a single server-sided script in ServerScriptService, but it looks like you're using value objects out of convenience, and I don't know if that isn't something you would want to or need to change if you did.
Instead of creating a new part, you should store the dollar bill in ReplicatedStorage with the script already inside of it, and clone it from there.