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

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

Asked by 4 years ago
Edited 4 years ago

--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)

0
Consider rewriting this question so it's more specific and correctly formatted. crywink 419 — 4y
0
@crywink hope I fixed it... Christopher_magical 9 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Ad
Log in to vote
0
Answered by 4 years ago

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

0
Is There Anyother way becuase idk them.. Christopher_magical 9 — 4y
0
nope, you need to do research man Wiggles1305 49 — 4y

Answer this question