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

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

Asked by 4 years 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 6913 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited by Ziffixture 4 years 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 6913 — 4y
Ad

Answer this question