I’m making a First Person shooter, and I made it so that when a player dies they drop ammo. It drops the part, but only sometimes it will give you ammo, and it also doesn’t disappear on touch. Can anyone help?
here is the code:
local ammo = script.Parent
local ReplicatedStorage = game:GetService(‘ReplicatedStorage’)
local ammoEvent = ReplicatedStorage:WaitForChild(‘AmmoPickup’)
local function ammo_pickup(otherPart)
local humanoid = otherPart:FindFirstChild(‘Humanoid’)
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if humanoid and player then
local gun = humanoid.Parent:FindFirstChildWhichIsA(‘Tool’)
if gun then
ammoEvent:FireClient(player)
ammo:Destroy()
end
end
end
ammo.Touched:Connect(ammo_pickup)
Thank you for taking your time to help me.
Probably due to 1 of your sanity checks not being valid, try this perhaps?
local ammo = script.Parent
local Rep = game:GetService("ReplicatedStorage")
local ammoEvent = Rep:WaitForChild("AmmoPickup")
local function ammo_pickup(OtherPart)
local Player = game.Players:GetPlayerFromCharacter(OtherPart.Parent)
if Player then
local Character = OtherPart.Parent
if Character:FindFirstChildWhichIsA("Tool") then
ammoEvent:FireClient(Player)
ammo:Destroy()
end
end
end
ammo.Touched:Connect(ammo_pickup)
You do not need to add the param right here
ammo.Touched:Connect(ammo_pickup)
--do this
ammo.Touched:Connect() -- It still thinks it is an character hitting it
What are you talking about-
Touched
is an event, if you don’t connect it to something it won’t receive the function that’s called
If I do it like this:
ammo.Touched:Connect()
I’m calling an empty function here, which would probably result in a nil
value
I just noticed that ammo-pickup was a function LOL sorry
Try putting fireclient below ammo:Destroy()
Thanks for the help! I really appreciate it!