Hello, i made a screen gui and inside has a textButton. when the player clicks the button an ak-47 is cloned from ReplicatedStorage and put into the players backpack using a local script inside the textButton. The problem is that the gun is scuffed when its added to the players backpack. It doesnt do any damage or make any sounds.
Here is the script inside the TextButton that clones and adds it to the players backpack…
local player = game.Players.LocalPlayer
local tool = game.ReplicatedStorage.Weapons[“AK-47”]
script.Parent.MouseButton1Click:Connect(function()
if player then
local clone = tool:Clone()
clone.Parent = player.Backpack
end
end)
Perhaps there is a problem with the weapon itself? Does it still work if it’s inside of the Backpack upon game startup? If so it might be a problem relating to how the weapon sets itself up and it expects itself to just spawn inside the backpack on game startup.
That only caused more bugs. Now the weapon is invisible. The problem wasn’t really equipting the gun anyway. The problem is that my guns don’t do any damage if you shoot another player. They dont make any sounds either. But if i put them in starter pack instead of using the gui then they work fine so i know the guns arent the problem
The weapons work perfectly fine in my game. They are in starter pack. But i want to add a weapon selection gui instead of just having them in starter pack
The problem might be that the new weapon is being created by the client itself, and is thus not replicated to the Server. To fix this you’d need to tell the server to add the weapon to the player, rather then the client creating the clone.
I seen somewhere that using a remote event and a server script might work(it was something similar to my problem) But i dont know alot about scripting so i dont know how to do that
Your issue is that your gun doesn’t damage or play sounds, correct? This is most likely an issue with your gun and not so much your code to get a tool. It most likely has issues when being parented.
You might also want to look into RemoteEvents as @CodeJared suggested. If your gun is server sided (which I imagine it is), it’s most likely why it isn’t firing.
I’m going to go ahead and assume your gun is server sided for sounds and firing. This probably means the server doesn’t recognize that the tool is in the player’s Backpack.
I’d assume this would work:
You will need a LocalScript, a Script and a RemoteEvent under your TextButton object. LocalScript:
local player = game.Players.LocalPlayer
local tool = game.ReplicatedStorage.Weapons.ak47
local RemoteEvent = script.Parent.RemoteEvent
script.Parent.MouseButton1Click:Connect(function()
if player then
RemoteEvent:FireServer(tool) -- Fires RemoteEvent to the server.
end
end)
Script
local RemoteEvent = script.Parent.RemoteEvent
function GiveTool(player, tool)
if player then
local clone = tool:Clone()
clone.Parent = player.Backpack
end
end
RemoteEvent.OnServerEvent:Connect(GiveTool) -- Runs function when the event has been fired
Hey, so you should not use a local Script, because of Filtering Enabled, you can use a object value for the selected guns, and then fire a remote event, and by server side give the player the tools to their backpack, or equip them by character.Humanoid:EquipTool(toolhere)