Przypisywanie obiektów do graczy w Roblox (tycoon)

Stwórz Platformy w folderze Platforms. Do każdej platformy dodaj atrybut Taken – boolean oraz UserId – number

Na ServerScriptService stwórz skrypt, który przypisze wolną platformę graczowi

local places = game.Workspace:WaitForChild("Platforms")

local function AssignPlatform(player)
	for i, place in places:GetChildren() do
		if place:GetAttribute("Taken") then continue end
		place:SetAttribute("Taken", true)
		place:SetAttribute("UserId", player.UserId)
		place.PlaceGui.UserName.Text = player.Name
		return place
	end
	return nil
end

game.Players.PlayerAdded:Connect(function(player)
	local place = AssignPlatform(player)
	if not place then
		player:Kick("No place for you")
		return
	end
end)

Platform Script

local place = script.Parent

place.Touched:Connect(function(other)
	local char = other.Parent
	local player = game.Players:GetPlayerFromCharacter(char)
	if player then 
		if not place:GetAttribute("Taken") then return end
		local hum = other.Parent:FindFirstChild("Humanoid")
		if player.UserId == place:GetAttribute("UserId") then
			hum.Health += 1
		else
			hum.Health -= 1
		end
	end
end)

Scroll to Top