Tool doesn't work?

For some reason, when this tool is granted from the proximity prompt, it doesn’t work.
When it’s put in starter pack and NOT granted through a proximity prompt, it works?
What’s even weirder is using this same script, the proximity prompt works with the med kit tool completely fine but with the pistol tool, it doesn’t.
Here is the behaviour of the pistol


Behaviour with the med kit:

Pistol behaviour without proximity prompt:

Pistol pick-up script:

script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
	local pistol = game.ServerStorage["Pistol"]:Clone()
	pistol.Parent = plr.Backpack
	task.wait(0.5)
	script.Parent:Destroy()
end)

Medkit pick-up script:

script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
	local medkit = game.ServerStorage["Med-Kit"]:Clone()
	medkit.Parent = plr.Backpack
	script.Parent:Destroy()
end)
2 Likes

How do you get the player on the gun’s script? Are you waiting for the player to equip the tool? Or directly getting the parent of the gun before it actually gets parented to the payer? Or only getting the parent of the gun (backpack) and not the actual player? Anyways, check for differences between the Med-Kit script and the gun script, I don’t think it has to do with the way you give it to the player.

1 Like

Check if the cloned pistol has scripts in it. Also I noticed in the pistol script it has a wait function, maybe that has to do with the bug?

1 Like

I don’t think that’s the problem because the tool seems to be working fine when put in starterpack

The pistol tool has the scripts in it

1 Like

Yeah you’re right, if it’s a local script the script would automatically be activated when it’s in the player’s backpack and the script would get the player as intended. In any case, I don’t think it has to do with the scripts he shown.

1 Like

Try adding prints inside the scripts. And check if they get printed.
(Also this might sound dumb but check if the scripts are enabled)

2 Likes

This is so strange, the script appears to run before the tool is equipped.
And I’ve checked backpack and it seems like when the tool is equipped it removes itself from backpack?

Can you show us the script in the cloned pistol?

Local script:

local remaining = game.ReplicatedStorage.Remaining
local reloadrt = game.ReplicatedStorage.Reload
local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local plr = game:GetService("Players").LocalPlayer
local tool = script.Parent
local playergui = plr.PlayerGui
local firerate = 0.5
local debouncereload = false
local uis = game:GetService("UserInputService")
local debounce = false
local maxammo = 16
local value = plr.Bulletpack.Bullet
local char = plr.CharacterAdded:Wait()
local ammo_out = false
local rt = game.ReplicatedStorage.Shoot
local ammo = 16
tool.Equipped:Connect(function()
	screengui1 = game.ReplicatedStorage.AmmoGui:Clone()
	screengui1.Parent = playergui
	screengui1.Enabled = true
	 text = screengui1.Frame.Ammo
	text.Text = tostring(ammo) .. "/" .. maxammo
	if value.Value <= ammo then
		text.Text = tostring(value.Value) .. "/" .. maxammo

	end
	
		end)
tool.Unequipped:Connect(function()
	screengui1:Destroy()
end)
tool.Activated:Connect(function()
	if debounce == true then return end
	if value.Value == 0 then
		text.Text = "Out of Ammo"
		return
	end
	ammo -=1
	if ammo == 0 and value.Value > 0 then
		text.Text = "Reloading"
		task.wait(2)
		ammo = 16
		if ammo > value.Value then
			text.Text = value .Value.. "/" .. maxammo
		end
		if value.Value > ammo then
			text.Text = ammo .. "/" .. maxammo
		end
	end
	print("oh hell nawh")
	rt:FireServer(mouse.Hit.Position, script.Parent)
	if value.Value > ammo then
		text.Text = tostring(ammo) .. "/" .. maxammo
	end
	if ammo > value.Value then
		text.Text = value.Value .. "/" .. maxammo
	end
	debounce = true
	task.wait(firerate)
	debounce = false
end)

Server script:

local rt = game:GetService("ReplicatedStorage"):WaitForChild("Shoot")
local reloadrt = game.ReplicatedStorage.Reload
local debris = game:GetService("Debris")
local gunshot = game:GetService("SoundService"):WaitForChild("Gun Shot")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://13112812781"
local debounce = false
local ammoout = false
local configfolders = script.Configuration
local reload = game.SoundService["Reload Sound"]
rt.OnServerEvent:Connect(function(plr, mouse, tool)
	print("aa")
	local bullets = plr.Bulletpack.Bullet
	local char = plr.Character
	local hum = char.Humanoid
	local animator = hum.Animator
	local effect = tool.Effect.MuzzleEffect
	local foundchild = configfolders:FindFirstChild(tool.Name)
	local damagedebounce = false
	if debounce == false and bullets.Value > 0 and ammoout == false then 
		bullets.Value -=1
		print("op")
		print(bullets.Value)
		foundchild.Ammo.Value -=1
		print(foundchild.Ammo.Value)
	local part = Instance.new("Part")
		part.Transparency = 1
		part.Anchored = true
	part.CanCollide = true
		part.Size = Vector3.new(1,1,1)
	part.Position = mouse
		part.Parent = workspace
		local animationid = foundchild:WaitForChild("AnimId").Value
		local reloadanimationid = foundchild.ReloadAnim.Value
		local animation = Instance.new("Animation")
		animation.AnimationId = animationid 
		local animator = plr.Character.Humanoid.Animator
		local loadanim = animator:LoadAnimation(animation)
		loadanim:Play()
		effect.Enabled = true
		gunshot:Play()
		if foundchild.Ammo.Value == 0 then
			reload:Play()
			print(foundchild.Ammo.Value)
			local animationreload = Instance.new("Animation")
			animationreload.AnimationId = reloadanimationid
			local loadanim = animator:LoadAnimation(animationreload)
			loadanim:Play()
			ammoout = true
			effect.Enabled = false
			print("op")
			while true do
				foundchild.Ammo.Value = 0
				task.wait(2)
				break
			end
			if foundchild.Ammo.Value >=  bullets.Value then
				foundchild.Ammo.Value = bullets.Value
			else
				foundchild.Ammo.Value = foundchild.MaxAmmo.Value
				
			end
			reload:Stop()
			ammoout = false
		end
		part.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				if hit.Parent.Name == plr.Name then return end
				if damagedebounce == false then
					hit.Parent.Humanoid:TakeDamage(foundchild.Damage.Value)
					damagedebounce = true
					end
			end
		end)
		debounce = true
		task.wait(foundchild.FireRate.Value)
		gunshot:Stop()
		part:Destroy()
		debounce = false
		effect.Enabled = false
		end
end)

This is logic if it’s a server script EDIT: no it’s not

This is an automatic roblox thing, when the tool is equipped it gets parented to the character when unequipped it gets parented to the backpack.

2 Likes

But for some reason the local script runs a .Activated event before the tool is even activated.

make a variable to check if the tool is equipped or nah
and before you do anything in the Activated tool, check if that variable is true. Maybe that could help

1 Like

Tried to make a variable to check that but it still did not work.

Wait, you’re only checking if the debounce is true, then returning, try adding an if statement to check if the debounce is false

Try doing

local char = plr.Character or plr.CharacterAdded:Wait()
2 Likes

That makes the same thing, return, stops the function. and the way you’re telling it runs the function without doing anything.

1 Like

The pistol tool still does not function.

add prints and see if anything gets printed

2 Likes

Done that, it prints before the tool is equipped or activated