New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Give a tool to player through GUI button doesnt work for me?

Asked by 14 days ago

Hello, I'm using this script:

local price = script.Parent.Parent.Price
local tools = game.ReplicatedStorage:WaitForChild("Tools")
local tool = script.Parent.Parent.ItemName
local player = script.Parent.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
    if player.leaderstats:findFirstChild("Money").Value >= price.Value then
        player.leaderstats:findFirstChild("Money").Value = player.leaderstats:findFirstChild("Money").Value - price.Value
        game.ReplicatedStorage.ShopBuy:FireServer(tool.Value)
    end
end)

but when I click the button, the script take the money from the player but doesnt give the item in the player's inventory.

0
You can't leave us without the Script that is responsible for actually giving the Item... Feahren 3662 — 14d

1 answer

Log in to vote
0
Answered by 14 days ago
Edited by Feahren 14 days ago

it might be that you haven't actually made the character equip the tool. this can be done like this:

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
Humanoid:EquipTool(workspace.Tool)

More info can be found here

0
I hope you don't mind me fixing up some stuff^•^ Feahren 3662 — 14d
Ad

Answer this question