Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is There A Way To Give An Item When U Click A Screen Gui (Buy Button)?

--For Example

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function(click) if player.leaderstats.Coins.Value >= 25 then player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 25

    game.ReplicatedStorage.Tools.GravityCoil:Clone().Parent = player:WaitForChild("Backpack")
end

end)

2 comments

0

Consider rewriting this question so it's more specific and correctly formatted.

0

@crywink hope I fixed it...

2 answers

✓ Accepted answer

Here.

Insert a remote event into ReplicatedStorage and insert a local script into the buy button.

Local script:

script.Parent.MouseButton1Click:Connect(function()
       game.ReplicatedStorage.RemoteEvent:FireServer()
end)

Now, insert a script into ServerScriptService.

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
local gravityCoil = game.ReplicatedStorage.Tools:WaitForChild("GravityCoil"):Clone()
gravityCoil.Parent = player:WaitForChild("Backpack")
end)

Please upvote and select this as your answer if it works.

this does not work because this is a local script and as such the tool will only appear on the client and not the server, you need to fire a remote event to make it appear on the server and client

2 comments

0

Is There Anyother way becuase idk them..

0

nope, you need to do research man

This discussion is preserved as it was. New answers, comments, and votes are closed.