Good day,
i make a game, and i use Shared data for my Shop(For the Coin and for what axe are the player is actuall on), but i have the problem that the player.SetResource() Mehod only work at the Money(Scripts down bellow.)
Thanks for any help,
good day.
Scripts:
--Save Money Script
local data = script:GetCustomProperty("Luberjackdata")
function OnPlayerJoined(player)
local storage = Storage.GetPlayerData(player)
local sharedStorage = Storage.GetSharedPlayerData(data, player)
local Coins = sharedStorage["Coins"] or storage["Coins"]
if Coins then
--print("Spieler hat Coins")
player.SetResource(player, "Coins", Coins)
elseif not Coins then
--print("Spieler hat keine Coins!")
player.SetResource(player, "Coins", 0)
end
end
function OnPlayerLeft(player)
local storage = Storage.GetSharedPlayerData(data, player)
storage["Coins"] = player:GetResource("Coins")
Storage.SetSharedPlayerData(data, player, storage)
end
Game.playerJoinedEvent:Connect(OnPlayerJoined)
Game.playerLeftEvent:Connect(OnPlayerLeft)
---SaveAxesScript
local data = script:GetCustomProperty("Luberjackdata")
function OnPlayerJoined(player)
local storage = Storage.GetPlayerData(player)
local sharedStorage = Storage.GetSharedPlayerData(data, player)
local actuallAxe = sharedStorage["actuallAxe"] or storage["actuallAxe"]
if actuallAxe then
--print("Spieler hat Coins")
player.SetResource(player, "actuallAxe", actuallAxe)
elseif not actuallAxe then
--print("Spieler hat keine Coins!")
player.SetResource(player, "actuallAxe", 0)
end
print(actuallAxe)
end
function OnPlayerLeft(player)
local storage = Storage.GetSharedPlayerData(data, player)
storage["actuallAxe"] = player:GetResource("actuallAxe")
Storage.SetSharedPlayerData(data, player, storage)
end
Game.playerJoinedEvent:Connect(OnPlayerJoined)
Game.playerLeftEvent:Connect(OnPlayerLeft)
--BuyAxe (2)
local Weapon = script:GetCustomProperty("Axe_2")
local data = script:GetCustomProperty("Luberjackdata")
local Trigger = script.parent
function BoughtItem(trigger, player)
local storage = Storage.GetPlayerData(player)
local sharedStorage = Storage.GetSharedPlayerData(data, player)
local Coins = sharedStorage["Coins"] or storage["Coins"]
local actuallAxe = sharedStorage["actuallAxe"] or storage["actuallAxe"]
local Minus = nil
Minus = Coins -100
if actuallAxe == 1 then --SharedData
if Coins >= 100 then
player.SetResource(player, "Coins", Minus)
player.SetResource(player, "actuallAxe", 2)
for _, equipment in ipairs(player:GetEquipment()) do
equipment:Unequip()
local weapon = World.SpawnAsset(Weapon, {})
weapon:Equip(player)
end
end
end
end
Trigger.interactedEvent:Connect(BoughtItem)