GUI Tool Giver Not Working

I’m making a game using ACS, where players click a button in a GUI that corresponds with a weapon and gives them said weapon.

1.When a button in a GUI is pressed it gives them a tool located in server storage.

2.When the button is pressed the tool is not given to the player. Error message is " Players.Airirusu.PlayerGui.VCGui.RIFLES.LocalScript:5: attempt to index nil with ‘Clone’ "

3.I tried moving the tool from server storage to things like replicated storage, and the weapon does get put into the inventory, but ends up being broken.

Im using a local script inside the button.

local item = game.ServerStorage:WaitForChild("M16",0.1)
local db = true
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	item:Clone().Parent = plr.Backpack
end)
3 Likes

Local scripts can’t access the ServerStorage folder, move it to ReplicatedStorage instead.

2 Likes

what do you mean by that? the tool can’t be used or what?

Try this:

local item = game.ServerStorage:WaitForChild("M16",0.1)
local db = true
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
     local newtool = item:Clone()
     newtool.Parent = plr.Backpack
end)

Edit: Might be because you just used item:Clone().parent. I don’t know

local item = game.ReplicatedStorage:WaitForChild("M16",0.1)
local db = true
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	item:Clone().Parent = plr.Backpack
end)

try changing the parent to replicated storage. usually that works better

ServerStorage cannot be accessed in a LocalScript. So basically game.ServerStorage would return nil in a LocalScript.

The tool can be equiped but it breaks something in acs that prevents it from being fired

I cant move into replicated storage bc then the weapon breaks and is unusable

It didnt work, it just showed the same error

Do >

Client scriopt >

 local item = game.ServerStorage:WaitForChild("M16",0.1)
local db = true
local plr = game.Players.LocalPlayer
local Event = game.ReplicatedStorage:WaitForChild("ToolGiverRemote")
script.Parent.MouseButton1Click:Connect(function()
	Event:FireServer(item)
end)

Server Script [ Place in ServerScriptService I guess ]

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("ToolGiverRemote")
Event.OnServerEvent:Connect(function(Player, Item)
if Item ~= nil then
if Item:IsA("Tool") then
game:WaitForChild("ServerStorage")[Item.Name]:Clone().Parent = Player:WaitForChild("Backpack")
end
end
end)

Make sure to add ToolGiverRemote Event into ReplicatedStorage [Put Remote Event and name it ToolGiverRemote]

This should work, as stated in the script you may need to change the player around to fit your gui.

Edit - forgot to add something to the code it should work now.

-- server script inside of a text button or image button
script.Parent.MouseButton1Down:Connect(function()
	local item = game.ServerStorage:WaitForChild("M16")
	local db = true
	local plr = script.Parent.Parent.Parent.Parent -- you might need to change plr depending on how many parents up from the script there are
	item:Clone().Parent = plr.Backpack
end)

Buddy I really don’t get how that isn’t working maybe roblox place/experience is bugged or something, or it could be where you define the model right here

Quote for your script

I mean I made basically what you’re coding and got no errors so I don’t see where you went wrong here’s a video.

https://streamable.com/sj8mtr

Didnt work there was no error message