I have a store ingame that is purchased with tools.
How do I get this Tool to be visible with everyone in game
Everytime I try, its not working
The code has a intvalue named Price and a String Value for the name
There is a Remote event in Replicated Storage called 'GiveTool'
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 createPartEvent = rs:WaitForChild("GiveTool") 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
The issue here is that you put the lines which give the player the tool in a localscript. Now, since I'm not sure whether the "GiveTool" remote event actually gives the player the tool or is used outside the script, I'm just going to make a separate RemoteEvent just in case.
Here is the code:
CLIENT
local player=game.Players.LocalPlayer local leaderboard=player:WaitForChild("leaderstats") local button=script.Parent local price=button:WaitForChild("Price") local item=button:WaitForChild("ItemName").Value local rs=game:GetService("ReplicatedStorage") local createPartEvent = rs:WaitForChild("GiveTool") button.MouseButton1Click:connect(function() if leaderboard.Coins.Value>=price.Value then leaderboard.Coins.Value=leaderboard.Coins.Value-price.Value --[[item:Clone().Parent=player.StarterGear item:Clone().Parent=player.Backpack]]-- rs.GiveThePlayerTool:FireServer(item) end end) while wait()do button.Text=item.Value.."-"..price.Value end
SERVER
game.ReplicatedStorage.GiveThePlayerTool.OnServerEvent:connect(function(plr,item) item:Clone().Parent=plr.StarterGear item:Clone().Parent=plr.Backpack end)
As you can see, now since the code actually granting the player the tool is in a ServerScript, everyone would be able to see the change as its happening to every player on the server, not just happening on the client. I hope this helps!