Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
TrollD3 105
9 years ago

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
0
Is it a Local script? You have a lot of problems but we need to know if your script is local... EzraNehemiah_TF2 3552 — 9y
0
its local TrollD3 105 — 9y
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. EzraNehemiah_TF2 3552 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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()!

0
WOO! ACCEPT THIS ONE THIS ACTUALLY HAS AN EXPLANATION! EzraNehemiah_TF2 3552 — 9y
0
Warning! The first script is actually going to clone the tool once, every click! Meaning the player CAN have multiples of said tool! alphawolvess 1784 — 9y
0
Down vote Anthony's answer. He did not have an explanation for his answer. EzraNehemiah_TF2 3552 — 9y
0
THANK YOU SOO MUCH TrollD3 105 — 9y
0
Ty, No problem. alphawolvess 1784 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

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)
0
Please explain HOW this works EzraNehemiah_TF2 3552 — 9y

Answer this question