where exactly did u put the prints?
After the .Activated and .OnServerEvent
I took all his prints to prove he did it.
try to put the fireserver event between the debounces
(yeah ik im giving random stuff as solutions idk what to say tbh)
What do you mean by putting it between the debounces?
between the lines debounce = true and debounce = false in local script
I’m so confused, why is this not working?
i’m confused too, i have no idea tbh
So, to make this clear as possible: Right now you have a pistol and a Med-Kit, the Med-Kit works but with the pistol equipped mid game, from what I understand, the .Activated event fires even when the tool is unequipped and it does nothing (<-- not sure about this part).
How to properly get help?
- How to properly give your scripts
script can be very long and and have a bunch of things that aren’t related to the question. With the whole script, it can be difficult to read.
-
Remove the parts of the script that are certainly not related to the problem. Do not do this technique much, just use it on big parts that have no correlation, in your case you can remove the else if statements that check what to display on the pistol UI.
-
Give comments, very important for people to read your scripts, without them it’s very hard to understand what is supposed to happen.
-
Be patient
It can take time for people to understand what’s the problem so be patient.
People who help are like behind a window. they don’t have access to the other side of it (the game) but they can see what you show and say, be as precise as possible to help people understand well. -
In the worst case, give access to the game or a copy of it. This is going to make people even more able to help you because the window will be broken. Restrain to using it a lot, if people are out of ideas for days, you can, but some bad people can copy the project and upload it to Roblox with lots of robux purchases, use this as a last resort.
Thanks for reading, I don’t know why I’m wrote this here, anyways I hope this helps a bit. Sorry for bad English.
Is anyone able to help with this?
I would like to help, its a little complicated to follow the progress you guys made, and the issue seems simple, its weird its not working. Im not the best but Im good at troubleshooting, maybe I could supply my little grain of help.
Could you point me out to the issue and scripts related?
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)
This is the script for the pistol when cloned into the backpack
The pistol doesn’t work at all when cloned and put into the backpack but when put in starter pack it works completely fine.
As stated before, its almost sure that script is not issue.
Seems that the issue is when the scripts inside the Pistol runs after being parented to backpack as already suggested.
Which are those scripts in the pistol and in the medpack?
Pistol scripts:
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)
I could break down the scripts if it’s needed
Here is the medkit script:
script.Parent.Activated:Connect(function()
if game.ServerStorage:FindFirstChild(script.Parent.Parent.Name .. " DYING").Value == true then
game.ServerStorage:FindFirstChild(script.Parent.Parent.Name .. " DYING").Value = false
script.Parent:Destroy()
end
script.Parent.Handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if game.ServerStorage:FindFirstChild(hit.Parent.Name .. " DYING").Value == true then
game.ServerStorage:FindFirstChild(hit.Parent.Name .. " DYING").Value = false
script.Parent:Destroy()
end
end
end)
end)
I could be asking for too much, but you could share the medpack and pistol model as a file so I can test the same approach you are using. Meanwhile I could use those scripts to test it. I could say Im trustable, honestly I dont need to steal any model or script from others, you could send it on DM or in here if you wish, if not, its ok, Im gonna give it a check to the scripts you provided and test it out
I can give you access to the game.
Just press the play gui button and go the house, you’ll find the pistol that clones into your backpack there and just click on it. Then try it out. Now try out the pistol that spawns when you join in(starter pack pistol).
If you find a medkit in the house click on the part and then take your health to 10 using the red part and activate the med kit by equipping it and clicking on it.
Its useless join the game, I would need access to studio or the files including remotes. But its ok if you cant, Im setting up the tools, scripts, remotes, disabling what its useless to test, etc. Maybe I could find the issue while doing this before to make them fully work
I disabled animations, sounds (cause Im not allowed to play those cause I dont own them), created a quick gui for the pistol, and disabled many stuff that is irrelevant for the test. And as expected works normally when giving the Pistol to player by using the Proximity Prompt, 100% its not related with giving it by Proximity or not.
There are plenty of issues with the scripts in the Pistol.
Well, first, there is a serious issue with the logic on how the bullets are handled.
Why the player has a value called “Bullet” holding the number of bullets, if the pistol itself contains a Configuration folder holding all those attributes?
You are checking the amount of bullets from 2 sides at the same time, from that Bullet value and the Ammo value in the pistol, that causes weird glitches when using it.
Then you hardcoded the client script in pistol, ignoring the Ammo in pistol, and ignoring the Bullets in player and just setting 16 in the client script, along with the other properties as FireRate, MaxAmmo, etc that are already in the pistol, but you added them hardcoded in the client script too.
I changed the hardcoded stuff to obbey the data inside the tool.
The logic is wrong when you are comparing the Bullets vs the Ammo to decide on client side to update the GUI.
Does the pistol at least contains a folder called “Configuration” and inside that folder a folder called Pistol and inside of it the values Ammo, MaxAmmo, FireRate, Damage etc?
The prints works normally in this video after giving the Pistol with your ProximityPrompt script, which is proof the Pistol scripts are messy, and should be rebuilt:
These are the changes I made to make them work on my side, but I didnt fix the logic when Tool.Activated, so it acts funny due to the unecesary double values to check the ammo, but the prints are proof that works
ServerScript Pistol:
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 -- twice
--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 -- twice
--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)
ClientScript Pistol:
--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 playergui = plr.PlayerGui
local debouncereload = false
local uis = game:GetService("UserInputService")
local debounce = false
local value = plr.Bulletpack.Bullet -- BULLETS IN PLAYER FROM ANOTHER SCRIPT
local char = plr.Character or plr.CharacterAdded:Wait() -- FIRST CHECK CHARACTER THEN CHARACTER ADDED
local ammo_out = false
local rt = game.ReplicatedStorage.Shoot
-- CONFIG DATA FROM TOOL FOLDER VALUES
local configfolders = script.Parent.Script.Configuration:FindFirstChild(tool.Name)
local maxammo = configfolders.MaxAmmo.Value
local ammo = configfolders.Ammo.Value
local firerate = configfolders.FireRate.Value
local screengui1
local text
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 = maxammo
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)
The ProximityPrompt:
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)
And I could mention lots of issues related with those Pistol scripts, I would suggest learn more about scripting and rebuild that pistol system which is very messy. You could make them work as I did yeah, but kinda useless if are going to act wonky… And requires to rebuild to work better, or stick with them and just rebuild specially the client logic to be in sync with the server logic. Make sure the Pistol has all the values inside of it, and the logic being based on those values not hardcoded stuff or taking in count another values in Player that makes no sense when compared with the Pistol values
Thank you so much! My client side script was an absolute mess and I agree with that.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.