I need to convert this script from a PlayerAdded gun giver to a gun giver where you have to click on a brick. When I attempt to do this, the gun successfully goes into my inventory, but the scripts don’t load for some reason. I’m wondering if I’m making errors or not because my click detector script does not fully load in the scripts. Not sure if this is my scripting error or loading errors. Here is the fresh script that I need to convert:
local sss = script.Parent
local guns = {
sss[“AR-15”],
sss[“M4A1”],
}
local replicate = Instance.new(“RemoteEvent”,game.ReplicatedStorage)
replicate.Name = “Replicate”
local start = Instance.new(“RemoteEvent”,game.ReplicatedStorage)
start.Name = “Start”
game.Players.PlayerAdded:Connect(function( p )
p.CharacterAdded:connect(function( c )
script.Parent.Replicator:Clone().Parent = c
start:FireClient(p,nil)
for i,v in pairs(guns) do
local gun = v:Clone()
gun.Parent = p.Backpack
start:FireClient(p,gun.Objects)
gun.Global.Disabled = false
end
end)
end)
Here’s it in the context of your code in case you’re having trouble implementing it:
local sss = script.Parent
local guns = {
sss[“AR-15”],
sss[“M4A1”],
}
local replicate = Instance.new(“RemoteEvent”,game.ReplicatedStorage)
replicate.Name = “Replicate”
local start = Instance.new(“RemoteEvent”,game.ReplicatedStorage)
start.Name = “Start”
--Add this
local ClickDetector = game.Workspace.Part.ClickDetector --This should be the location of wherever the click detector instance is in the game
--Event changed to a click detector (the rest of the code, besides the events binding the function to a Player/Character Added, is unchanged)
ClickDetector.MouseClick:Connect(function(p)
local c = p.Character
script.Parent.Replicator:Clone().Parent = c
start:FireClient(p,nil)
for i,v in pairs(guns) do
local gun = v:Clone()
gun.Parent = p.Backpack
start:FireClient(p,gun.Objects)
gun.Global.Disabled = false
end
end)
As you can see, the click-detector tool giver does not load in the gui, and the other scripts. But the player-join tool giver loads in everything perfectly. Why is this? Is there a solution to this? I’m pretty sure that this is a loading problem.
This may be due to the scripts inside of your guns.
Maybe try adding a repeat wait() until Model.Parent.ClassName ~= WHEREVER
Some of your code may be running as soon as the game starts and not as soon as the player receives their gun. Also, have you tried checking Output or the Developer Console for any errors?
I have a feeling that it may be due to the way your guns are coded - I know you may not want to share your gun code but maybe try looking through and seeing if the problem stems from there.