How would i go about this?

so i have a folder, and inside the folder are balls, there is a string value inside the balls that has the player’s name. i want to make it so the player can only touch the ball with their string value in them. i have tried looping through a script and making it find out whose ball is it, but there is always a delay. any idea what i can do for this?

2 Likes

Could you post the script here? Then it would be a lot easier to know whats wrong

--//Serivces
local Players = game:GetService("Players")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Balls = workspace:WaitForChild("Balls")
wait(1)
--//Functions
local function OnBoulderAdded(boulder)
	print(boulder:GetChildren())
	if boulder.Plr.Value == LocalPlayer.Name then
		return
	end

	boulder.CanTouch = false
	boulder.CanCollide = false
end

Balls.ChildAdded:Connect(OnBoulderAdded)

for i, boulder in ipairs(Balls:GetChildren()) do
	task.spawn(OnBoulderAdded, boulder)
end
1 Like

i feel like theres a simpler and faster way of doing this

I don’t think you need to use task.spawn here, but i can’t find any other problems in your code

here’s the game: Obby but you're Sisyphus [WIP] - Roblox
the ball that spawns after you spawn is the one with the player’s name on it, the other one is without

Have a local scrip with a function that has (player)

Have the part have can colide off and have if localplayer.name==player.name

Cancolide =true

But have it be part.touched:connect(that function)

if the collision is off it would just go through the map the second the player spawn in

Sorry i thought theyd be ancherd

no its ok its a very difficult problem

So i was half right use collostion filtering Collision Filtering | Documentation - Roblox Creator Hub

seems inpractical to create a collision group for each player isn’t it?

can you join the game rq i think i found a answer

I cant right now you make one collistion group for all the players then add them to a table when they join

but then i would make to make a group for each ball too

Add each players ball into a table

any other ideas? i feel like making it into a table is unnessearyily complicated

Another way of doing “player only” touch detection is by connecting the .Touched event on the client directly. Steps could look like this:

  1. On the server, have a table of players as keys and their ball references
  2. Send the ball references to the clients, so for example:
--ON THE SERVER
local tableOfBalls = {[player1] = {ball1, ball2, ball3}, [player2] = {ball4, ball5, ball6}}

for _, player in Players:GetPlayers() do
    remoteEvent:FireClient(player, tableOfBalls[player]))
end
...

--ON THE CLIENT
remoteEvent.OnClientEvent:Connect(function(tableOfBalls)
	for _, ball in tableOfBalls do
		ball.Touched:Connect(function(object)
			... do code here
		end)
	end
end)
  1. Then when a client touches the ball, fire the ball reference to the server
  2. On the server, verify if the ball is owned by the client (check if the ball exists in their table) and done

im out rn, ill try this when i get home, seems like it could work

1 Like