How can I make it so that when the player comes in contact with the block, his MouseIcon is disabled. This works for me, but when a player comes in contact with it everyone in the server can't see their cursor.
h = workspace.DisableCursor function touch(hit) if hit then h:FindFirstChild("Humanoid") game.GetService("UserInputService").MouseIconEnabled = false end end h.Touched:Connect(touch)
You should make it local for the player, and you're trying to access UserInputService
in a server script so it changes for the entire server. To make it local, you first need to add a RemoteEvent
into ReplicatedStorage
.
In this case, I'll call it DisableMouse as game.ReplicatedStorage.DisableMouse
(It's a Remote Event)
You can put the RemoteEvent inside a folder or anything but you have to change the locator (e.g. workspace.Part3). Here is your modified Server script:
First, we need to find the player who touches it. Then fire the remote event only to that player who touched it, so only that player will have their cursor disabled.
Also when you do anything like :GetService, :FindFirstChild
it must have a colon (;) instead of .GetService or .FindFirstChild
h = workspace.DisableCursor function touch(hit) if hit ~= nil then if hit.Parent:FindFirstChild("Humanoid") ~= nil then -- Found humanoid? local plr = game.Players:GetPlayerFromCharacter(hit.Parent) game.ReplicatedStorage.DisableMouse:FireClient(plr) -- Fire the remote event for the player who touched part's client end end end h.Touched:Connect(touch)
Add a Local Script in StarterPlayerScripts
game.ReplicatedStorage.DisableMouse.OnClientEvent:Connect(function() game:GetService("UserInputService").MouseIconEnabled = false -- When told to by server, disable mouse icon. end)
Thank you