I’m kind of stuck how to access the library information when the button is touched. The library is so named because it will be mapped to the players playerstats, Button[playerstats.Name] or something like that so that way I can easily update the playerstats values later on in the script. I hit a snag when I don’t know how to access the library using the name of the button “FireButton” for example to correspond to ButtonFire in the library. Any help would be appreciated.
local ButtonDataMapping = require(game:GetService("ReplicatedStorage").ButtonDataModuleScript)
local CollectionService = game:GetService("CollectionService")
local taggedParts = CollectionService:GetTagged("TaggedButtons")
local gameButtons = game.Workspace.Buttons
local waitTime = 1
-- separate the elemental buttons for resetting values after cost analysis
local elementalButtons = {
FireButton = gameButtons.FireButton,
FireModButton = gameButtons.FireModButton,
WaterButton = gameButtons.WaterPowerButton,
WaterModButton = gameButtons.WaterPureButton,
EarthButton = gameButtons.EarthPowerButton,
EarthModButton = gameButtons.EarthEnrichmentButton,
AirButton = gameButtons.AirPowerButton,
AirModButton = gameButtons.AirQualityButton,
}
-- Tagged buttons are scripted together --
for _, tagged in pairs(taggedParts)do -- get all buttons that are tagged
local db = true
tagged.Touched:Connect(function(otherPart)
local player = game:GetService("Players"):GetPlayerFromCharacter(otherPart.Parent)
if player and db then
db = false
local buttonTouched = tagged.Parent
-- checking whether the tagged part is elemental or not
-- this is because elemental buttons don't reset other elemental buttons
local isElemental = false
local key = nil -- The key to access the ButtonDataMapping
for butName, butValue in pairs(elementalButtons) do
if buttonTouched.Name == butValue.Name then
isElemental = true
break
end
end
-- get button cost here
--[[
if isElemental then
print("Button is Elemental "..buttonTouched.Name)
else
print("Button is not Elemental "..buttonTouched.Name)
end
when the player touches the button
first thing is to check if they have enough currency
this means getting the button cost first from the module script
using the button name as reference
check button name against module?
get the players energy
if the player has enough energy then continue
the cost increases each time the player buys the button
this is where the rate of change comes in
new button cost = button base cost * rate of change
need to loop through the players available currency each time the player
buys the button
remove the cost
continue buying the button until the players currency < new cost
after that set the players currency to 0
and any other currencies the button needs to reset - if isElemental = true
]]
task.wait(0.05)
db = true
end
end)
end
Module Library Information
-- Version 1.0
local ButtonDataMapping = {
ButtonFire = {
ButtonName = "FireButton",
ButtonCost = 1000,
ButtonValue = 0.25,
RequiredCurrency = "Energy",
RateOfCostChange = 4,
DisplayCost = game.Workspace.InformationBoards.Fire.FireDisplay.SurfaceGui.Cost,
DisplayCurrentRank = game.Workspace.InformationBoards.Fire.FireDisplay.SurfaceGui.CurrentRank,
DisplayPerRank = game.Workspace.InformationBoards.Fire.FireDisplay.SurfaceGui.PerRank,
},
...
-- Further library data...