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

How to make the mouse icon change?

Asked by 5 years ago

Before you read this im new at lua scripting and roblox studio so have than in considerament. Thank you for understanding.

So im trying to make a script to change the mouse icon, but idk why it isn't working. Im using a local script lol. P.S.if there's anything that's writed wrong its because i cant go to roblox studio right now and copy my code. Anyways... here's the code.

ThE cOdE :

local player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:getMouse()

game.StarterPack.Gun.equipped:connect(function()
      mouse.Icon = "rbxassetid://358948941"
end

The idea is when the gun is equipped the mouse icon change, but it isn't working, pls help me fixing this.

2 answers

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
5 years ago

First, you're reusing code that's already been defined. Why don't you just do player:GetMouse(). Variables are there for you to use.

Second, you're not accessing the gun that's being equipped. You're connecting the Equip event to the gun in StarterPack. Think of StarterPack as a folder that only copies it's children when a new character spawns. StarterPack isn't something a local player has access to.

If this is a local script and inside a Tool object, then the Tool you want to access can be found using script.Parent.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local Tool = script.Parent

Tool.Equipped:Connect(function()
    print("This tool was equipped")
    mouse.Icon = "rbxassetid://358948941"
end)

Equipped event also has a parameter that is the mouse of the player. So you wouldn't need to use line 2.

Take note of how you type your code. GetMouse, Connect, and Equipped should always be capitalized since other forms might be considered deprecated.

0
you can also use the parameter of the Equipped event to get the player's mouse User#23365 30 — 5y
0
I commented on that right below my code. xPolarium 1388 — 5y
Ad
Log in to vote
0
Answered by
aazkao 787 Moderation Voter
5 years ago
Edited 5 years ago

starterpack doesnt belong to the player, backpack does, when a player equips their tool, the tool they are equipping is in the backpack of the player, you can see by going to Players>mewantataco>backpack

i assume this is a local script inside the tool so just do

script.Parent.Equipped:Connect(...)
0
Thank you mewant_taco 17 — 5y

Answer this question