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
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.
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.
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?
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)
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