I'm working on a shop system for my game and I've already got most of the system done, but I've added boolvalues in ReplicatedStorage, so that when it sends data to the main game, you'll will spawn will those items you purchased. I've already scripted it, but it does nothing. It's supposed to find the boolvalue in ReplicatedStorage by using the tower name you just purchased.
Here's the script. Thanks a lot, notreallysupernova.
local coin = workspace.Coin
local errorSoundEffect = workspace.Error
local Price = script.Parent.Parent.TowerPrice
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
if player.leaderstats:FindFirstChild("Coins").Value >= Price.Value then
-- player.leaderstats:FindFirstChild("Coins").Value = player.leaderstats:FindFirstChild("Coins").Value - Price.Value
coin:Play()
-- Here is where I tried to write where tries to find a object in ReplicatedStorage by it's name.
for _, Tower in pairs(game.ReplicatedStorage.OwnedTowers:GetChildren()) do
if Tower.Name == script.Parent.Parent.TowerName then
Tower.Value = true
print(Tower.Value)
end
end
else
errorSoundEffect:Play()
end
end)

1 comment
It doesn't work. It gives an error saying "attempt to index nil 'value'"