Part not showing for all players

So I have a game where I want a part to appear around the player and cover them. This works, however, when it happens, no other player can see the part, and they can walk right through it. How would i make it so that all players can see it, and no walking right through it happens? I have the scripts, just need a certain way to fix this. (These are local scripts btw)

local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local keycode = Enum.KeyCode.E
local glove = script.Parent
local rock = game.Workspace.Rock
local equipped = false


glove.Equipped:Connect(function()
	equipped = true
end)

glove.Unequipped:Connect(function()
	equipped = false
end)


UIS.InputBegan:Connect(function(key, gp)
	if key.KeyCode == keycode then
		if UIS:GetFocusedTextBox() == nil then
			if equipped == true then
				rock.Position = plr.Character.HumanoidRootPart.Position
				plr:GetChildren().CanCollide = false
				plr.Character.Torso.Anchored = true
				script.Enabled = false
				script.Parent.UndoAbility.Enabled = true
			end
		end
	end
end)
local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local keycode = Enum.KeyCode.E
local glove = script.Parent
local rock = game.Workspace.Rock
local equipped = false

glove.Equipped:Connect(function()
	equipped = true
end)
glove.Unequipped:Connect(function()
	equipped = false
end)

UIS.InputBegan:Connect(function(key, gp)
	if key.KeyCode == keycode then
		if UIS:GetFocusedTextBox() == nil then
			if equipped == true then
				if script.Parent.Ability.Enabled == false then
					rock.Position = Vector3.new(14899.731, 1231, -17.899)
					plr:GetChildren().CanCollide = true
					plr.Character.Torso.Anchored = false
					script.Parent.Ability.Enabled = true					
					script.Enabled = false
					plr.Character.Humanoid.WalkSpeed = 5
					wait(1.5)
					plr.Character.Humanoid.WalkSpeed = 16
				end
			end
		end
	end
end)
1 Like

You need to do this on the server.

1 Like

yes, but how would i go about doing that? like what i need is not full scripts, just some way or hint to how to change them

1 Like

The problem is, when you create a part on the client (local scripts), it will only be visible for that player only. It is not replicated to the server, and therefore no one else will be able to see it. This is also the same reason why exploiters can delete parts for their game only, but no one else would be able to see it.

You would need to use Remote Events to tell the server that you want the part to be created for that specific player.
Create a remote event, and place it in Replicated Storage
Then create a server script and place it in a container such as ServerScriptService

Not gonna give the whole code, but in your local script define the Remote event

local RS = game:GetService("ReplicatedStorage")
local RemoteEvent = RS:WaitForChild("RemoteEvent")

then in your InputBegan function, replace the line rock.Position = Vector3.new(14899.731, 1231, -17.899) with code that fires the remove event. For example,

RemoteEvent:FireServer(rock)
-- you can organise the parameters however you want idk

In your server script, simply setup the connection to detect invokes from the client

-- In a Server-script / script
RemoteEvent.OnServerEvent:Connect(function(Player, Rock)
	Rock.Position = Player.Character.HumanoidRootPart.Position
end)

Even better practise would be to FireAllClients from the server and change the Rock.Position from the client, since you shouldn’t really be directly modifying visual changes on the server (but there’s already lots of information on that if you google). I don’t think you’ll need to modify stuff such as the WalkSpeed or anchored properties of the character on the server since the client has full control of the Players physics and characters anyways (last time I checked).

1 Like

Don’t pass as it will not replicate. (Assuming you created the rock on client)

1 Like

In his script rock is a reference to the Instance in workspace

local rock = game.Workspace.Rock
2 Likes

ok so it works, the only problem is that the rock stays where the player was. i have a slight idea on how to fix that i just need some help with it

1 Like

You can create a weld by script between the Rock and the HumanoidRootPart. Something as simple as this.

RemoteEvent.OnServerEvent:Connect(function(Player, Rock)
	Rock.Position = Player.Character.HumanoidRootPart.Position
	local weld = Instance.new("WeldConstraint")
	weld.Part0 = Rock
	weld.Part1 = Player.Character.HumanoidRootPart
	weld.Parent = Rock
	Rock.Anchored = false
end)
1 Like

Hello! On your LocalScript that you provided (the one with the UserInputService functions), it only makes the ability locally. To fix this, you can add a RemoteEvent and fire it to toggle the rock’s visibility. However, this isn’t the best approach as it is spammable by exploiters.

The best way to fix this is to make the rock.Position = Vector3.new(14899.731, 1231, -17.899) code be on the ServerScript and reference the player through there.

As I assume you’re recreating the Slap Battles diamond glove, I’d highly recommend creating an AbilityHandler script in ServerScriptService to better manage ability script whilst easily referencing the Player, Character and Glove scripts (which would also solve the client-sided rock visibility issue).

2 Likes

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