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

Tool not working when given from an equip gui but works when in starter pack?

I have made a textbutton GUI to give a player a tool into their backpack. The tool is given but does not work, I placed it in the starter pack and it functions works well. There are no errors or mistakes in the script. It just does not work

I think it has something to do with filtering enabled...

Script:

local used = false
local desuboru = game.ReplicatedStorage.Attacks.Desuboru

script.Parent.MouseButton1Click:Connect(function()
	if used == false then
		local clone = desuboru:Clone()
		clone.Parent = game.Players.LocalPlayer.Backpack
		used = true
	else
		script.Parent.Text = "Equipped"
		wait(1)
		script.Parent.Text = "Equip"
	end
end)

Please help!

2 answers

✓ Accepted answer

I assume your script is a local script, it's a typical remote event question.

1.Add a remote event in ReplicatedStorage called BackpackEquip.

2.Add a server script inside ServerScriptService called Event_Listener

Basically what you should do is that you need to connect the server to the client signal.

--server script--
game.ReplicatedStorage.BackpackEquip.OnServerEvent:Connect(
function(plr,toolName)
	if not plr.Character then--If there's no character
		return nil--stop the function
	end
	
	if toolName then
		--Equip
		if plr.Backpack:FindFirstChild(toolName) then
			plr.Backpack:FindFirstChild(toolName).Parent = plr.Character
		else
			--unknown tool
			warn("Player has no tool called " .. toolName)
		end
	else
		--Dequip if there is no tool whose name is this name.
		local found = plr.Character:FindFirstChildWhichIsA("Tool")
		if found then
			found.Parent = plr.Backpack
		end
	end
end)

Then your local script:

--local script--
local used = false
local desuboru = game.ReplicatedStorage.Attacks.Desuboru

script.Parent.MouseButton1Click:Connect(function()
	if used == false then
		game.ReplicatedStorage.BackpackEquip:FireServer(desuboru.Name)--or just "Desuboru" lol haha
		used = true
	else
		script.Parent.Text = "Equipped"
		wait(1)
		script.Parent.Text = "Equip"
	end
end)

Ohh there some works to change!

P.S. if you want to dequip the tool then just do:

game.ReplicatedStorage.BackpackEquip:FireServer(nil)

1 comment

0

I tried on the server but didn't clone on server , thanks a lot!

Hey so. In order for a tool to clone to the server, you will have to fire a RemoteEvent. Your code should resemble something like this:


--LOCAL SCRIPT

local used = false
local desuboru = game.ReplicatedStorage.Attacks.Desuboru
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "ToolGiver"
remoteEvent.Parent = game.ReplicatedStorage
	 
	script.Parent.MouseButton1Click:Connect(function()
	    if used == false then
	       remoteEvent:FireServer("Equipped")
	        used = true
		script.Parent.Text = "Equipped"
	    else
	   
	
	        script.Parent.Text = "Equip"
		remoteEvent:FireServer("Unequipped")
		used = false
	    end
	end)

:

-- SERVER SCRIPT IN SERVERSCRIPTSERVICE

game.ReplicatedStorage["ToolGiver"].OnServerEvent:Connect(function(plr, value)
	if value == "Equipped" then
		clone = game.ReplicatedStorage.Attacks.Desuboru:Clone()
		clone.Parent = plr.Backpack
	else
		plr.Backpack.Desuboru:Destroy()
	end
end)

Hope this helped. Trust me I know how annoying FE can be some times. xD

4 comments

0

Your version is clear and helpful! However a more flexible method is via tool name or custom identifiers.

0

Yeah I know thanks for the feedback though. Very helpful. Have a nice day :D

0

:D THANKS!

0

Kinda back tracked myself on this I created the RemoteEvent via the client. You should do it on the server script

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