So im having a bit of trouble at the moment. For some odd reason the enemy in my game only drops the tool the first time i kill him. I have the tool drop chance to 100% but he only drops it the first time he dies then it never drops again. Any idea whats going no?
if not reward.Stats:FindFirstChild("Prompt") or not reward.Stats.Prompt.Value then
obj.Disabled = true
end
end
end
dropBlock.Handle.CFrame = CFrame.new(position)
wait(.2)
local anchor = Instance.new("Part")
anchor.Name = "AnchorPart"
anchor.Size = Vector3.new(2, 2, 2)
anchor.Transparency = 1
anchor.Anchored = true
anchor.CanCollide = false
anchor.Parent = model
anchor.CFrame = CFrame.new(dropBlock.Handle.Position) * CFrame.new(0, 1.5, 0)
if player.Character then
anchor.CFrame = CFrame.new(anchor.Position, Vector3.new(
player.Character.Head.Position.X,
anchor.Position.Y,
player.Character.Head.Position.Z))
anchor.CFrame = anchor.CFrame * CFrame.Angles(0, math.pi * 2 * amountNum / amount, 0)
anchor.CFrame = anchor.CFrame * CFrame.new(0, 0, 3) -- Place it farther from the player
end
wait(.1)
if not reward.Stats:FindFirstChild("Prompt") or not reward.Stats.Prompt.Value then
anchor.Touched:Connect(function(part)
if part.Parent ~= nil and part.Parent.Name == recipient and part.Name == "HumanoidRootPart" and touched == false then
if Players:FindFirstChild(recipient) then
touched = giveItem(reward.Name, recipient)
if touched == true then
model:Destroy() -- Remove model after collected
sendInventoryUpdate(player)
else -- Inventory full
print('inventory full')
end
else
model:Destroy()
end
end
end)
else
reward.Prompt.Parent = anchor
anchor.Prompt.Triggered:Connect(function(player)
touched = giveItem(reward.Name, recipient)
model:Destroy() -- Remove model after collected
sendInventoryUpdate(player)
end)
end
1 Like
Hi!
Which section of your script, does the checks of when it should drop a tool or not?
I posted this part of the code because everything was working fine until the prompt got added into the code.
So when the prompt is triggered, they will receive the item?
And it’s that specific part which isn’t working?
Yes. The tool goes into the inventory after the prompt is triggered. And im not 100% sure if that specific code is the issue as it was a add on to my existing system (commission) i just know before the prompt was put in everything was working as intended. But there are more lines of code which can be causing the issue but theres just so much code.
I would suggest adding prints before every “if” statement that you think could cause the problem.
Print a index, followed by the values you’re printing so you know where your prints ended easily.
print(1, reward.Stats:FindFirstChild("Prompt"), reward.Stats.Prompt.Value)
Then you manually can check up on if something is wrong.
Ok so, inside the tool is a folder called “stats”. in that folder is a boolvalue named “prompt”, the proximity prompt only pops up for the tool if the value is checked marked, i just unchecked it to turn the proximity prompt off and he drops the tool everytime i kill him. so the value seems to be the issue
Go testplay your game, and check if your BoolValue’s value changes like you want it to, while you play. If it doesn’t change how you want to the 2. time you want the enemy to drop the tool, then go into your script, locate where you change the BoolValue’s value, and check the if-statements before that, and see if they go through.
Everything looks good, the only error i see after i try to get the tool to drop a 2nd time is
03:17:32.513 Prompt is not a valid member of Tool "ServerStorage.Pickups.Melee.Classic Sword" - Server - DamageControl:333
Go on Line 333, In this case it tells you that Prompt is not a part of Classic Sword, have you checked if the prompt is present?
These are lines 333-349. Everything looks fine. Prompt is present inside of the tool.
reward.Prompt.Parent = anchor
anchor.Prompt.Triggered:Connect(function(player)
touched = giveItem(reward.Name, recipient)
model:Destroy() -- Remove model after collected
sendInventoryUpdate(player)
end)
end
Do you do like commissions or anything?
Here’s what’s going on in the script.
reward.Prompt.Parent = anchor -- This is the Classic Sword you defined here.
--And it tells us that "Prompt" isn't a part of Classic Sword
--Try adding either a WaitForChild to wait for the prompt to be a part of anchor (Classic Sword) or use FindFirstChild to check if it's present
local Prompt = anchor:WaitForChild("Prompt")
Prompt.Triggered:Connect(function(player)
touched = giveItem(reward.Name, recipient)
model:Destroy() -- Remove model after collected
sendInventoryUpdate(player)
end)
Still doesn’t work unfortunately. He drops it the 1st tike but wont drop it again.
But it shouldn’t print an error now, correct?
I just dont get why he drops it once but not after that. It says its not a prt of classic sword but it still drops the first time.
Did you do as I said, by using WaitForChild?
I used both waitforchild and findfirstchild. same results for both.
Show me the part of the script again please.
this is what you meant by adding waitforchild or findfirstchild?