Button click store.
Store works in the original code but no1 sees the tool but the Original person who purchased the tool, the tool is invisible to everyone else.
How do I get the code to work where a remote event is passed through?
Thanks in advance.
Orignial code:
local player=game.Players.LocalPlayer local leaderboard=player:WaitForChild("leaderstats") local button=script.Parent local price=button:WaitForChild("Price") local item=button:WaitForChild("ItemName") local rs=game:GetService("ReplicatedStorage") button.MouseButton1Click:connect(function() if leaderboard.Coins.Value>=price.Value then leaderboard.Coins.Value=leaderboard.Coins.Value-price.Value local item=rs:WaitForChild(item.Value) item:Clone().Parent=player.StarterGear item:Clone().Parent=player.Backpack end end) while wait()do button.Text=item.Value.."-"..price.Value end
New code in local script for button with REMOTE Event. The RemoteEvent is named tool [inside the button]
local player=game.Players.LocalPlayer local leaderboard=player:WaitForChild("leaderstats") local button=script.Parent local price=button:WaitForChild("Price") local item=button:WaitForChild("ItemName") local rs=game:GetService("ReplicatedStorage") local tool = script.Parent -- the tool local createPartEvent = rs:WaitForChild("tool") button.MouseButton1Click:connect(function() if leaderboard.Coins.Value>=price.Value then leaderboard.Coins.Value=leaderboard.Coins.Value-price.Value local item=rs:WaitForChild(item.Value) createPartEvent:FireServer(tool) end end)
ServerScript for passing RemoteEvents [In the ServerScriptService]
local button=script.Parent local price=button:WaitForChild("Price") local item=button:WaitForChild("ItemName") local rs=game:GetService("ReplicatedStorage") local tool = script.Parent -- the tool local createPartEvent = rs:WaitForChild("tool") createPartEvent.OnServerEvent:Connect(function(player,tool) game:GetService("ReplicatedStorage"):WaitForChild(item.Value) item.Clone().Parent = player.StarterGear -- poof! item:Clone().Parent=player.Backpack -- poof! wait(3) -- poof! end)
The reason the tool is only showing up on one player (the client) is because of FilteringEnabled. The problem with the original script is that you're using a LocalScript to clone the tool and place it inside the client's inventory.
It's definitely not the only problem here. On your new script, you have the client handle the transaction and then fire the remote event to have the server clone the item. This is more of a security risk but isn't what you're asking.
Here's what you should do.
Have a LocalScript that listens for the Button to be clicked and then fire the RemoteEvent.
The server script should be in ServerScriptService if u want to be smart. u only put it in lighting if u want ur script to be lit af.
Have the script listen for the RemoteEvent being fired. Then, it should remove the money from the player's data and clone the item and parent it to the player's inventory.
Here's a example of how the server script should look
local Event = game.ReplicatedStorage:FindFirstChild("Event") local Cost = 1 local Tool = game.ServerStorage:FindFirstChild("Homosexuality") Event.OnServerEvent:Connect(function(Player) local Data = FunctionThatGetsPlayerData(Player) if Data.Money >= Cost then Data.Money = Data.Money - Cost local PlayerTool = Tool:Clone() PlayerTool.Parent = Player.Backpack return true end
this isn't tested because i don't wanna open robloxstudio
If this helped, Accept this answer or feel my wrath.
Server Scripts shouldn't be in the PlayerGui.. Put the Server Script in ServerScriptService, and on line 3 you assigned "item" a value but changed it in line 11.