Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Disabling MouseIcon on Touch only for the player who touches the block?

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)

1 answer

✓ Accepted answer

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

1 comment

0

Thanks a lot! This is exactly what I was looking for! I'd love to give you an upvote but I can't do that yet.

This discussion is preserved as it was. New answers, comments, and votes are closed.