I was wondering if this script would work for a shop GUI it will check if you have the required stats(In this case checking weather you bought or not since this is using datastore I used Intvalues.) So i was wondering what I need to change to give me the item
local tool = ("tool") function clicked(player) local stats = player:FindFirstChild("Towers") local sp = stats:FindFirstChild("Towers") if sp == nil then return false end if (sp.Value >= 1) then tool:clone().parent = player.backpack end end game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function() clicked(player) end) end)
You have to use remote events; insert a localscript in the button with the following text:
local replicatedstorage = game:GetService("ReplicatedStorage") local event = replicatedstorage:WaitForChild("toolevent") -- name this to the toolevent local tool = replicatedstorage:WaitForChild("Tool") -- toolname local button = script.Parent local player = game.Players.LocalPlayer local mouse = player:GetMouse() local stats = player:WaitForChild("Towers") local sp = stats:WaitForChild("Towers") -- considering this is your intvalue button.MouseButton1Click:Connect(function() if sp.Value >= 1 then event:FireServer(mouse.Hit) end end)
Then insert a serverscript inside of serverscriptservice with the following text
local replicatedstorage = game:GetService("ReplicatedStorage") local event = replicatedstorage:WaitForChild("toolevent") -- name this to the toolevent local tool = replicatedstorage:WaitForChild("Tool") -- toolname event.OnServerEvent:Connect(function(player,mouse) local stats = player:WaitForChild("Towers") local sp = stats:WaitForChild("Towers") -- considering this is your intvalue if sp.Value >= 1 then tool:Clone().Parent = player:WaitForChild("Backpack") sp.Value = sp.Value - 1 end end)