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

How would I script this Replicated Storage stuff? {ANSWERED} THANK YOU

I am making create a class menu gui. I have tools in replicated storage but i dont know how to script it so that when a player clicks on the text button, the weapon is in the backpack. Also how would I script a different button that would remove all the selected weapons? This is my code so far. I know it not much. it is incomplete and btw kf5dot is the name of one of the weapons.

function Click(mouse)
	local KF5Dot = game.ReplicatedStorage:
end

3 comments

0

Is it a Local script? You have a lot of problems but we need to know if your script is local...

0

its local

0

TrollD3, tell me how does the answer work. What is LocalPlayer what is MouseButton1Click what is clone and what is FindFirstChild. Did you learn anything. Do not accept answers if they do not have an explanation.

2 answers

✓ Accepted answer

Let's disregard what you did because your script is heavily incomplete, no call is being taken place, plus this is not how you'd activate the function by pressing a ScreenGui.

I do Not know you hierarchy, so I cannot say my script will go to the correct places, but I'll make it so you need to put it inside of the TextButton.

This is to be for a LocalScript ! Make sure the tools are inside of 'ReplicatedStorage' ! Look bellow this script for information!

sp = script.Parent
player = game.Players.LocalPlayer


sp.MouseButton1Click:connect(function()
	local KF5Dot = game.ReplicatedStorage:FindFirstChild("KF5Dot"):Clone()
	KF5Dot.Parent = player.Backpack
end)

Due to this being a LocalScript, we can use LocalPlayer which is pretty helpful. Now, doing KF5Dot.Parent = will assign where this clone is going to, in this case, the players Backpack.

Now, to clear our the tools in the Backpack, you'd do this script (Still a LocalScript inside of a TextButton)

sp = script.Parent
player = game.Players.LocalPlayer


sp.MouseButton1Click:connect(function()
	local All_Tools = player.Backpack:GetChildren()
	for _, Tool in pairs(All_Tools) do
		Tool:remove()
	end
end)

This script is going through each item in your backpack using a Generic For loop, then removing them. for _,Tool- Tool is actually going to be the Tool in backpack, which is why I did Tool:remove()!

5 comments

0

WOO! ACCEPT THIS ONE THIS ACTUALLY HAS AN EXPLANATION!

0

Warning! The first script is actually going to clone the tool once, every click! Meaning the player CAN have multiples of said tool!

0

Down vote Anthony's answer. He did not have an explanation for his answer.

0

THANK YOU SOO MUCH

0

Ty, No problem.

Get a local script and put it in the button and put this in the local script :3

player = game.Players.LocalPlayer

function click()
	weapon = game.ReplicatedStorage:FindFirstChild("WeaponNameHere"):clone()
	weapon.Parent = player.Backpack
end

script.Parent.MouseButton1Click:connect(click)

1 comment

0

Please explain HOW this works

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