this piece of code works when there’s 1 player, not when there’s 2 or more. only part that works is the collision group one(only one that wasnt written by me, coincidence???)
--in SSS
RS.InitBase.OnServerEvent:Connect(function(player)
print("player "..player.Name.." got their base loaded via clientfire")
for i, v in Tycoons do
if v.Gate:GetAttribute("HasOwner") == true then
if v.Gate:GetAttribute("Owner") == player.UserId then
break
end
break
end
if v.Gate:GetAttribute("HasOwner") == false then
print("attempted to set "..v.Name.." to "..player.Name)
if not PhysicsService:IsCollisionGroupRegistered(i) then
PhysicsService:RegisterCollisionGroup(i)
end
if not PhysicsService:IsCollisionGroupRegistered(player.UserId) then
PhysicsService:RegisterCollisionGroup(player.UserId)
PhysicsService:CollisionGroupSetCollidable(i, player.UserId, false)
end
if player.Character then
for i, descendant in ipairs(player.Character:GetDescendants()) do
if descendant:IsA("BasePart") then
descendant.CollisionGroup = player.UserId
end
end
end
v.Gate:SetAttribute("HasOwner", true)
v.Gate:SetAttribute("Owner", player.UserId)
v.Gate.CollisionGroup = i
v.Gate.CanCollide = true
v.Gate.Color = Color3.fromRGB(170, 0, 0)
RS.BaseLoaded:Fire(player, v)
break
end
end
Tried to rewrite it now it doesnt work at all im stumped
RS.InitBase.OnServerEvent:Connect(function(player)
print("player "..player.Name.." got their base loaded via clientfire")
for i, v in ipairs(Tycoons) do
local owner = v.Gate:GetAttribute("Owner")
local gate = v.Gate
if owner ~= nil then
print("gate of "..v.Name" is owned, finding next")
return("fake")
end
if owner == player.UserId then
print("player already has a base")
return("fake")
end
if not owner then
if not PhysicsService:IsCollisionGroupRegistered(i) then
PhysicsService:RegisterCollisionGroup(i)
end
if not PhysicsService:IsCollisionGroupRegistered(player.UserId) then
PhysicsService:RegisterCollisionGroup(player.UserId)
PhysicsService:CollisionGroupSetCollidable(i, player.UserId, false)
end
if player.Character then
for index, descendant in ipairs(player.Character:GetDescendants()) do
if descendant:IsA("BasePart") then
descendant.CollisionGroup = player.UserId
end
end
end
v.Gate:SetAttribute("Owner", player.UserId)
v.Gate.CollisionGroup = i
v.Gate.CanCollide = true
v.Gate.Color = Color3.fromRGB(170, 0, 0)
RS.BaseLoaded:Fire(player, v)
end
end
end)
EDIT: I modified your code a little bit and added some debug prints. Could you try this?
--in SSS
RS.InitBase.OnServerEvent:Connect(function(player)
print("Player " .. player.Name .. " got their base loaded via client fire")
local foundTycoon = false
for i, v in ipairs(Tycoons) do
if v.Gate:GetAttribute("HasOwner") == true and v.Gate:GetAttribute("Owner") == player.UserId then
-- Player already owns this base, no need to continue, you can do whatever you want here.
foundTycoon = true
print("[0] Found tycoon.")
break
end
if v.Gate:GetAttribute("HasOwner") == false then
print("[0] HasOwner false, continue.")
if not PhysicsService:IsCollisionGroupRegistered(player.UserId) then
PhysicsService:RegisterCollisionGroup(player.UserId)
print("[0] Registered collision group for player: " .. player.UserId)
end
if not PhysicsService:IsCollisionGroupRegistered(i) then
PhysicsService:RegisterCollisionGroup(i)
print("[0] Registered collision group for base: " .. i)
end
if player.Character then
for _, descendant in ipairs(player.Character:GetDescendants()) do
if descendant:IsA("BasePart") then
descendant.CollisionGroup = player.UserId
print("[0] Set collision group for character part: " .. descendant.Name)
end
end
end
v.Gate:SetAttribute("HasOwner", true)
v.Gate:SetAttribute("Owner", player.UserId)
v.Gate.CollisionGroup = player.UserId
v.Gate.CanCollide = true
v.Gate.Color = Color3.fromRGB(170, 0, 0)
print("[0] SetAttributes correctly done")
RS.BaseLoaded:Fire(player, v)
foundTycoon = true
print("[0] Base assigned to player: " .. player.UserId)
break
end
end
if not foundTycoon then
print("[1] Couldn't find a suitable tycoon for player: " .. player.UserId)
end
end)