Hi, I’m new to scripting, I keep getting this error on line 18 and I don’t really know how to fix this, anyone know the solution ?
local data = game:GetService("DataStoreService"):GetDataStore("TowerDataStore")
local remote = game:GetService("ReplicatedStorage"):WaitForChild("Tower")
remote.OnServerEvent:Connect(function(Player, value, value2, value3, value4)
if value == "Place" then
local tower = game:GetService("ReplicatedStorage").Towers[Player[value2].Value]:Clone()
tower.Indicator:Destroy()
tower.HumanoidRootPart.BodyPosition:Destroy()
tower.HumanoidRootPart.Anchored = true
tower.HumanoidRootPart.Position = value3 + Vector3.new(0, 2.80, 0)
tower.Parent = workspace
local originpart = Instance.new("Part", tower)
originpart.Name = "Originpart"
originpart.CanCollide = false
originpart.Anchored = true
originpart.Transparency = 1
originpart.Position = value3 + Vector3.new(0, 2.80, 0)
local statsGui = Player.PlayerGui.Tower:FindFirstChild(value4) --error here
print(value4)
if statsGui then
print("Found")
statsGui.Adornee = tower.HumanoidRootPart
remote:FireClient(Player, "EnableScripts")
end
end
end)
function save(plr)
local saveData = {}
for i,v in pairs(plr:GetChildren())do
if v:IsA("StringValue") then
saveData[v.Name] = v.Value
end
end
data:SetAsync(plr.UserId, saveData)
end
game.Players.PlayerAdded:Connect(function(plr)
for i = 1, 4 do
local x = Instance.new("StringValue", plr)
x.Name = "Tower"..tostring(i)
x.Value = "Empty"
end
local getData
local success, errorm = pcall(function()
getData = data:GetAsync(plr.UserId)
end)
if success then
if getData then
for i, v in pairs(getData) do
plr:FindFirstChild(i).Value = v
end
end
end
end)
game:BindToClose(function()
for _, v in pairs(game.Players:GetChildren())do
save(v)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
save(plr)
end)