Hi
Hi, I’m Sven and I made a Shop GUI.
So I’m making a script which makes the item add to a players inventory if they bought the item: if they have 1 star (the leaderstat, see it as coins)
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if player.leaderstats.Stars.Value >= 1 then
game.ServerStorage.ShopItems.FluffyUnicorn.Clone().Parent = game.player.backpack
end
end)
I have searched a lot (even youtube videos) but it can’t answer my question.
I’m not really good at scripting yet, but I hope someone can tell me what is wrong about my script.
Thank you for reading!
Note: this is a normal script inside of a textbutton
I made a folder named ShopItems inside of the ServerStorage with the item: FluffyUnicorn inside.
This is a local script right? Only the server can view the ServerStorage, so you should put the folder inside of ReplicatedStorage and clone it from there.
I did this in a normal script, but I will change it into a localscript & put the folder inside of the ReplicatedStorage. Will the issue be solved then?
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("RemoteEvent")
script.Parent.MouseButton1Click:Connect(function()
if player.leaderstats.Stars.Value >= 1 then
Event:FireServer()
end
end)
script
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("RemoteEvent")
Event.OnServerEvent:Connect(function(player)
ServerStorage.ShopItems.FluffyUnicorn:Clone().Parent = player.Backpack
end)
script.Parent.Activated:Connect(function()
local Event = Instance.new("RemoteEvent",game:GetService("ReplicatedStorage"))
Event:FireServer()
end)
Server Program
game:GetService("ReplicatedStorage").RemoteEvent.OnServerEvent:Connect(function(player)
if player:FindFirstChild("leaderstats") and player:FindFirstChild("leaderstats").Stars.Value >= 1 then
game.ServerStorage.ShopItems.FluffyUnicorn.Clone().Parent = player.backpack
end
end)