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)
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).
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).