local tycoons = game.Workspace.Tycoons:GetChildren() local Mod = require(game.ServerScriptService.TycoonModule) local Players = game:GetService("Players") function ClaimPlot(hit,v) local player = Players:GetPlayerFromCharacter(hit.Parent) if hit.Parent:FindFirstChild("Humanoid") then if player:FindFirstChild("HasClaim").Value == false then Mod.SetOwner(hit.Parent, v.Owner) player:FindFirstChild("HasClaim").Value = true v:WaitForChild("ClaimPart"):Destroy() else print("e") end end end -- End of function (ClaimPlot) function BuyObject(player,v) print(player.Name) end for i,v in ipairs(tycoons) do for i,s in ipairs(tycoons.Buttons) do --Here is the problem s.Click.ClickDetector.MouseClick:Connect(function(player) BuyObject(player,v) end) end end for i,v in ipairs(tycoons) do v.ClaimPart.Touched:connect(function(hit) ClaimPlot(hit,v) end) end local function PlayerLeave(player) for i,v in ipairs(game.Workspace.Tycoons:GetChildren()) do if player.Name == v:WaitForChild("Owner").Value then local Backup = game.ReplicatedStorage.BackupFolder.Tycoon local TycoonCFrame = v.Base.CFrame local NewTycoon = Backup:Clone() v:Destroy() NewTycoon.PrimaryPart = NewTycoon.Base NewTycoon.Parent = game.Workspace.Tycoons NewTycoon:SetPrimaryPartCFrame(TycoonCFrame) NewTycoon.ClaimPart.Touched:connect(function(hit) ClaimPlot(hit,NewTycoon) end) end end end game.Players.PlayerRemoving:Connect(PlayerLeave)
It won't loop thru the Buttons inside the line where it should have like -- Heres the problem Line 31 Can anyone help?
local tycoons = game.Workspace.Tycoons:GetChildren() local Buttons = game.Workspace.Tycoons.Tycoon.Buttons:GetChildren() local Mod = require(game.ServerScriptService.TycoonModule) local Players = game:GetService("Players") function ClaimPlot(hit,v) local player = Players:GetPlayerFromCharacter(hit.Parent) if hit.Parent:FindFirstChild("Humanoid") then if player:FindFirstChild("HasClaim").Value == false then Mod.SetOwner(hit.Parent, v.Owner) player:FindFirstChild("HasClaim").Value = true v:WaitForChild("ClaimPart"):Destroy() else print("e") end end end -- End of function (ClaimPlot) function BuyObject(player,v) print(player.Name) end for i,v in pairs(Buttons) do v.Click.ClickDetector.MouseClick:connect(function(player) BuyObject(player,v) end) end for i,v in pairs(tycoons) do v.ClaimPart.Touched:connect(function(hit) ClaimPlot(hit,v) end) end local function PlayerLeave(player) for i,v in pairs(game.Workspace.Tycoons:GetChildren()) do if player.Name == v:WaitForChild("Owner").Value then local Backup = game.ReplicatedStorage.BackupFolder.Tycoon local TycoonCFrame = v.Base.CFrame local NewTycoon = Backup:Clone() v:Destroy() NewTycoon.PrimaryPart = NewTycoon.Base NewTycoon.Parent = game.Workspace.Tycoons NewTycoon:SetPrimaryPartCFrame(TycoonCFrame) NewTycoon.ClaimPart.Touched:connect(function(hit) ClaimPlot(hit,NewTycoon) end) end end end game.Players.PlayerRemoving:Connect(PlayerLeave)
So Now I have another problem after getting that to work which is, whenever a player touches it aka claims, then leaves afterward. The new owner isn't able to click on it.