Issue to create a part for a local player [Script]

Edit : Hello, I have a problem with my script. I have placed a mesh part in the replicated Storage. When a player touches a part then the mesh part appears in the game locally. This part becomes unanchored, Cancollide true. The big problem is that : Yes the other players can’t see the mesh part, yes the other players can’t collide with the mesh part BUT strangely the other players can still move it by passing over it (while I remind him he doesn’t collide with it and doesn’t see it). What I would like is that the other players can’t move it. Does anyone know how I can fix this problem? I’ve seen some games using this mechanic so it must be possible
Sorry for my bad english i still learning english. Thank you
(Script below are not complet)

local plr = game.Players.LocalPlayer
local velocity = 5
local PlayerPart = game.ReplicatedStorage.basketball:Clone()

function onTouch6(hit)
	if hit.Parent.Name == plr.Name then 
		game.Workspace.basketback.CanTouch = false
		PlayerPart.Parent = game.Workspace
		PlayerPart.CanCollide = true
		PlayerPart.Anchored = false
	end
end
game.Workspace.basketback.Touched:Connect(onTouch6)
1 Like

There is nothing wrong, as you said, every client has their own part, so they can change the color, position and more. But others clients and server won’t see it.

Hello, you misunderstood what I said (and it’s normal I have difficulties to express myself in English). I reworded everything and added a script

He is saying other players can still walk over it and go on top and he wants to stop that.

So here’s what’s actually happening: the player is creating a part and touching it. Because the server trusts the player it will blindly accept that there is a part there and tell all the other players that the part exists. But because you’re only changing the cancollide and anchored properties on the client, it will only apply to the client, so nothing will change on the server.

Here’s how I would do this: create a part in a server script and make it invisible to all other players.

Server Script:

PlayerPart.Parent = game.Workspace

for i, v in pairs(game.Players:GetPlayers()) do
	PlayerPart.Anchored = false
	game.Workspace.basketback.CanTouch = false
	if v.Name == plr.Name then
		PlayerPart.Transparency = 0
		PlayerPart.CanCollide = true
	else
		PlayerPart.Transparency = 1
		PlayerPart.CanCollide = false
	end
end

This is only to make the part invisible. Use it as an example and implement your own version in your script.

Uh, no. You’ve got a fundamental misunderstanding of how replication works on Roblox.

Here is the actual scenario:

  1. The client is creating this clone of the part, locally.

  2. Since it’s local, they have full “NetworkOwnership,” therefore, the client simulates all the physics for the part (locally).

  3. When a different Player’s character interacts with the part, they tend to clip into it (you know, since they don’t actually simulate any collisions with it themselves), meaning the local client would simulate such, and it would move.
    They may also be able to jump around on the part and consequently fling it sometimes.

Yes, and it would tell the server that it touched the part, therefore the server will know that there is a part there.

The server doesn’t handle touched events, it trusts the client to tell it when a part has been touched.

Thanks for your answers, I will test your script and give you a feedback (and put solution if it work)

@Temateite @IDoLua Here is a great video by Suphi Kaner to learn more about client to server communication and how to prevent common exploits: Stop Hackers / Exploiters - Roblox Scripting Tutorial - YouTube. He also explains how the client communicates part collisions to the server.

1 Like