Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This script is to clone a gun on click yet I can get loads of the same? - [SOLVED]

This script is to clone a gun on click yet I can get loads of the same one I only want one is there a way to do that. This is the script that is in it

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	game:GetService("InsertService"):LoadAsset(5354029446):GetChildren()[1].Parent = player.Backpack
end

2 answers

✓ Accepted answer
local alreadyGotGun = {}
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if alreadyGotGun[player.Name] == nil then
    game:GetService("InsertService"):LoadAsset(5354029446):GetChildren()[1].Parent = player.Backpack
alreadyGotGun[player.Name] = true
end
end)

When a player clicks on the detector, if their name is not in the dictionary it gives them the gun and adds their name to the dictionary.

2 comments

0

Thanks for the help but it still manages to produce this error " Workspace.Gun Room.Guns.GunA.GiveItemScript:7: Expected ')' (to close '(' at line 2), got "

0

I fixed it.

local GunButton = script.Parent
local GunClickDetector = GunButton.ClickDetector
local InsertService = game:GetService("InsertService")
local GunID = 5354029446

local function GetGun(Player)
	if Player.Backpack:FindFirstChild("AR88") or Player.Character:FindFirstChild("AR88") then -- Only works if the model's name is AR88 
		for Index, Tool in pairs(InsertService:LoadAsset(GunID)) do
			Tool.Parent = Player.Backpack
		end
	end
end

This detects whether they already have the gun. The difference between my script and Racconyz's script is mine gives guns after people die and his only gives guns once and even if they rejoin, they still won't get new guns.

2 comments

0

script has no errors but it doesnt give it me at all so I dont know what happened

0

Fixed

This discussion is preserved as it was. New answers, comments, and votes are closed.