object.CollisionGroup = "Player" doesn't work (SOLVED)

  1. What do you want to achieve? I wanna set the eh player collision group

  2. What is the issue? It doesnt work, collide with players and zombies for my game

  3. What solutions have you tried so far? None yet

what’s wrong with my code

local Players = game:GetService("Players")
local PhysicsService = game:GetService("PhysicsService")

Players.PlayerAdded:Connect(function(player)
	local groupId = unknown because i dont want to show it
	local role = player:GetRoleInGroup(groupId)
	local cashValue = 500
	
	if role == "Owner 🔨" then
		cashValue = 1000000
	elseif role == "Developer / Admin 🔧🛡️" then
		cashValue = 100000
	elseif player:IsInGroup(groupId) then
		cashValue = 600
	end

	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = cashValue
	cash.Parent = player

	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = player

	local placedTowers = Instance.new("IntValue")
	placedTowers.Name = "PlacedTowers"
	placedTowers.Value = 0
	placedTowers.Parent = player

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local cashStats = Instance.new("IntValue")
	cashStats.Name = "Cash"
	cashStats.Value = cash.Value
	cashStats.Parent = leaderstats

	cash:GetPropertyChangedSignal("Value"):Connect(function()
		cashStats.Value = cash.Value
	end)

	cash.Changed:Connect(function()
		cashStats.Value = cash.Value
	end)

	player.CharacterAdded:Connect(function(character)
		for i, object in ipairs(character:GetDescendants()) do
			if object:IsA("BasePart") then
				object.CollisionGroup = "Player"
			end
		end
	end)
end)

1 Like

Make sure you use the inbuilt roblox collision group editor so they have the properties that you desire, in most cases you cant just create a collision group and set it a day, you need to set how players will collide with zombies via the editor


image

i already did that before, also i tested on my oldest version on my game and it works perfectly i even tried using the old script and it worked but ill lose all the changes of group, etc if i do that. (Mob is Zombie)
Captura de pantalla 2024-05-24 222938
Captura de pantalla 2024-05-24 222947

Make sure the zombies are properly being assigned the Mob collision group, check that and please get back to me.

i checked and it’s properly assigned to the Mob collision group
Captura de pantalla 2024-05-24 225231

Captura de pantalla 2024-05-24 225236

Captura de pantalla 2024-05-24 225241

i still need help in this issue… (I’m trying to see whats the problem. oh i see, for some reason collision works after player resets)

1 Like

Try setting the collision when the player enters the game and the player resets.(loadcharacter)

i mean:

local Players = game:GetService("Players")
local PhysicsService = game:GetService("PhysicsService")

Players.PlayerAdded:Connect(function(player)
	local groupId = unknown because i dont want to show it
	local role = player:GetRoleInGroup(groupId)
	local cashValue = 500
	
	if role == "Owner 🔨" then
		cashValue = 1000000
	elseif role == "Developer / Admin 🔧🛡️" then
		cashValue = 100000
	elseif player:IsInGroup(groupId) then
		cashValue = 600
	end

	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = cashValue
	cash.Parent = player

	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = player

	local placedTowers = Instance.new("IntValue")
	placedTowers.Name = "PlacedTowers"
	placedTowers.Value = 0
	placedTowers.Parent = player

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local cashStats = Instance.new("IntValue")
	cashStats.Name = "Cash"
	cashStats.Value = cash.Value
	cashStats.Parent = leaderstats

	cash:GetPropertyChangedSignal("Value"):Connect(function()
		cashStats.Value = cash.Value
	end)

	cash.Changed:Connect(function()
		cashStats.Value = cash.Value
	end)

for i, object in ipairs(player.Character:GetDescendants()) do
	if object:IsA("BasePart") then
		object.CollisionGroup = "Player"
	end
end

	player.CharacterAdded:Connect(function(character)
		for i, object in ipairs(character:GetDescendants()) do
			if object:IsA("BasePart") then
				object.CollisionGroup = "Player"
			end
		end
	end)
end)
1 Like

Thank you, it worked correctly!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.