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
01 | local tool = ( "tool" ) |
02 | function clicked(player) |
03 | local stats = player:FindFirstChild( "Towers" ) |
04 | local sp = stats:FindFirstChild( "Towers" ) |
05 | if sp = = nil then return false end |
06 | if (sp.Value > = 1 ) then |
07 | tool:clone().parent = player.backpack |
08 | end |
09 | end |
10 |
11 | game.Players.PlayerAdded:connect( function (player) |
12 | player.CharacterAdded:connect( function () |
13 | clicked(player) |
14 | end ) |
15 | end ) |
You have to use remote events; insert a localscript in the button with the following text:
01 | local replicatedstorage = game:GetService( "ReplicatedStorage" ) |
02 | local event = replicatedstorage:WaitForChild( "toolevent" ) -- name this to the toolevent |
03 | local tool = replicatedstorage:WaitForChild( "Tool" ) -- toolname |
04 | local button = script.Parent |
05 | local player = game.Players.LocalPlayer |
06 | local mouse = player:GetMouse() |
07 | local stats = player:WaitForChild( "Towers" ) |
08 | local sp = stats:WaitForChild( "Towers" ) -- considering this is your intvalue |
09 | button.MouseButton 1 Click:Connect( function () |
10 | if sp.Value > = 1 then |
11 | event:FireServer(mouse.Hit) |
12 | end |
13 | end ) |
Then insert a serverscript inside of serverscriptservice with the following text
01 | local replicatedstorage = game:GetService( "ReplicatedStorage" ) |
02 | local event = replicatedstorage:WaitForChild( "toolevent" ) -- name this to the toolevent |
03 | local tool = replicatedstorage:WaitForChild( "Tool" ) -- toolname |
04 | event.OnServerEvent:Connect( function (player,mouse) |
05 | local stats = player:WaitForChild( "Towers" ) |
06 | local sp = stats:WaitForChild( "Towers" ) -- considering this is your intvalue |
07 | if sp.Value > = 1 then |
08 | tool:Clone().Parent = player:WaitForChild( "Backpack" ) |
09 | sp.Value = sp.Value - 1 |
10 | end |
11 | end ) |