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

Can't seem to give a tool to someone. How would you give a tool after going through prerequisites?

Asked by 4 years ago

So I am trying to make a GUI (I've made the GUI and made it openable and all) that only has one button, all I want it to do is when clicked, see if you have enough of a set value (in my case it's called GBP) and if you have enough, remove 500 and then give you the tool (M1911)

This is how I am making it detect the click (my button is named S) And then verify the value

bg.S.MouseButton1Click:connect(function()
    if player.GBP.Value >= 8000 then

Can't seem to figure out how to make it clone the tool in the player's backpack from lighting if the player has enough and if the player doesn't have enough to cancel

3 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

To clone a tool (or anything that called as an object), we use :Clone() function. This function will copy the object it self, properties, child,etc... of the object. And then, you can move the tool to player backpack by using: Tool.Parent = game.Players.LocalPlayer.Backpack.

My advice is, you shouldn't storing anything in Lighting. Because, we have 2 service for that is ServerStorage and ReplicatedStorage.

Ad
Log in to vote
0
Answered by 4 years ago
bg.S.MouseButton1Click:Connect(function() -- Connects the clicked function
    local plr = game.Players.LocalPlayer -- references the player
    if plr.GBP.Value >= 8000 then -- if their stat is more than that
        game.ReplicatedStorage.ItemNameHere.Parent = plr.Backpack -- it puts the tool in their backpack
    end -- ends the if statement
end) -- ends the clicked function

This should work. If you have any problems or questions still, tell me them in the comments below.

All the best,

PrismaticFruits - obviously a very talented scripter

Log in to vote
0
Answered by
aredanks 117
4 years ago

Use ServerStorage for storage on Scripts instead of Lighting

To clone, use :Clone()

To make a player equip a tool, use Humanoid:EquipTool(tool)

Final code:

local m1911 = game.ServerStorage.M1911
local clonedWeapon = m1911:Clone()
clonedWeapon.Parent = workspace — doesn’t matter anywhere in workspace works it just needs to be inside workspace since it doesn’t work without a parent
local yourPlayer = — define your player instance
local humanoid = yourPlayer.Character.Humanoid
humanoid:EquipTool(clonedWeapon)

You may also put the cloned weapon’s parent as the player’s Backpack yourPlayer.Backpack but will not directly equip it but give it to the player in their backpack. Equipping directly will still add it to their backpack however as well.

Answer this question