Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Change Instance (Integer) that was made by a script using another?

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)

5 comments

0

Please post your code. It helps a lot.

0

Edited, not much, but that is why I posted here.

0

Will your shop be physical (a building obviously) or a GUI?

0

GUI. A Dialog GUI. It brings the shop up. I am trying to connect the buttons to reduce your credits,and clone the weapon from replicatedstorage.

0

I created the credits USING datastorage. How do I talk to that with the button script to further reduce the integer?

1 answer

###This will be a LocalScript under your TextButton or ImageButton. I will be using RemoteEvents and RemoteFunctions, 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)

###Server code, recommend to put it in 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)

###I won't give the full code. Though there's a basic understanding on how. Here's a few things that you should read.

https://devforum.roblox.com/t/changes-to-playing-ability-of-experimental-mode-games/146494.

http://robloxdev.com/articles/Remote-Functions-and-Events

3 comments

0

I have yet to test it, and I had not know about remote events. Thank you. I will test it soon.

0

Ok. By the way, CheckPrice is a RemoteFunction, whilst CloneTool is a RemoteEvent

0

Also, why do you need to get replicated storage? It's already game.ReplicatedStorage.

This discussion is preserved as it was. New answers, comments, and votes are closed.