I created an instance using another script. It was data storage. I created an integer, which were credits. I'm making a shop that reduces your credit amount when you buy a weapon. Since the instance was created with the earlier script, is there some way I can talk to that script using the shop button one?
game.players.PlayerAdded:Connect(function(player) game.Workspace.DataStore -- This is as far as I have gotten, and the only piece that is important. Are lines of code children of the script, "Datastore" or how do you talk to "leaderstats" or, "credits?" end)
LocalScript
under your TextButton
or ImageButton
. I will be using RemoteEvent
s and RemoteFunction
s, as ROBLOX may be removing experimental mode. Learn more on that here.local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local BuyRemotes = ReplicatedStorage:WaitForChild("BuyWeaponRemotes") --^ BuyWeaponRemotes is a Folder in ReplicatedStorage. local CheckPrice = BuyRemotes:WaitForChild("CheckPrice") local CloneTool = BuyRemotes:WaitForChild("CloneTool") local Price = CheckPrice:InvokeServer("Sword") -- ^We will be returning the price here, and "Sword" just change to weapon name. local player = Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function() -- Listens for the button being clicked CloneTool:FireServer("Sword", Price) end)
ServerScriptService
.local ReplicatedStorage = game:GetService("ReplicatedStorage") local BuyRemotes = ReplicatedStorage:WaitForChild("BuyWeaponRemotes") local CheckPrice = BuyRemotes:WaitForChild("CheckPrice") local Weapons = ReplicatedStorage:WaitForChild("Weapons") --^ Another folder inside replicatedstorage. Put your weapon in here. local CloneTool = BuyRemotes:WaitForChild("CloneTool") --[[ You may notice we don't have LocalPlayer. Do not use it on the server, only in LocalScripts. --]] local GetPrice = function(player, toolName) return Weapons[toolName].Price.Value -- Make sure an IntValue named price is inside the tool. end CheckPrice.OnServerInvoke = GetPrice CloneTool.OnServerEvent:Connect(function(player, toolName, price) --[[ up to you check if the player have more or enough, and the weapon cloning. --]] end end)
https://devforum.roblox.com/t/changes-to-playing-ability-of-experimental-mode-games/146494.