My script is only working for the client and not appearing for other players

My script is supposed to spawn a brick in front of the player, I will use this as a hitbox for a “knockback” powerup.

The script is only working locally, the brick only spawns for the client and not other players. The location is as follows:

image

Here’s a example of what’s happening
https://gyazo.com/426f726f9226b48012c20a956b016d46

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
	
	if input.KeyCode == Enum.KeyCode.Q then
		local RayOrigin = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
		local RayDestination = game.Players.LocalPlayer.Character.HumanoidRootPart.Position + game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.LookVector * 20
		local RayDirection = RayDestination - RayOrigin
		
		local ray = Ray.new(RayOrigin, RayDirection)
		local part = Instance.new("Part")
		local Distance = (RayOrigin - RayDestination).Magnitude
		part.Size = Vector3.new(5,5,Distance)
		part.Position = RayOrigin
		part.CFrame = CFrame.lookAt(RayOrigin + RayDirection /2, RayOrigin + RayDirection)
		part.Parent = workspace
		part.BrickColor = BrickColor.Red()
		part.Transparency = .5
		part.Anchored = true
		part.CanCollide = false
		Instance.new("Part")
		wait(5)
		part:Destroy()
		
	end
end)

Thanks in advance!

This is because of Filtering Enabled. As you’re using a LocalScript, the changes that you make will only be able to be seen by the client, and will not be replicated to the server. Therefore, I suggest using a RemoteEvent to send a request for this to be replicated on the server.

1 Like

You should only use the key pressing part for local script and, make it fire a remote event to a normal script that contains what you were suppose to do.

2 Likes

I can’t get the local player in a normal script though, How’s this supposed to work?

Well you could do:

RemoteEvent.OnServerEvent:Connect(function(plr) -- plr = the local player
1 Like

Thanks! That did the trick. :+1:

1 Like