Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

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. ItsJZaid 45 — 4y
Ad

Answer this question