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 6 months 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... Ziffixture 5655 — 6mo

1 answer

Log in to vote
0
Answered by 6 months ago
Edited by Ziffixture 6 months 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^•^ Ziffixture 5655 — 6mo
Ad

Answer this question