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

LocalScript I'm trying to get to run based around displaying a Tool's stats. What am I doing wrong?

Asked by 7 years ago

So, I'm trying to have a Gui display what item the character is holding (Its image, name and tooltip). Here's my script in its entirety:

local player = game.Players.LocalPlayer
local character = player.Character
if not character then
    character = player.CharacterAdded:wait()
end
character = player.Character

local frame = script.Parent.Frame
local image = frame.ItemImage
local name = frame.ItemName
local tooltip = frame.ItemToolTip

character.Changed:connect(function()
    if character:FindFirstChildOfClass("Tool") then
        name.Text = character:FindFirstChildOfClass("Tool").Name
        tooltip.Text = character:FindFirstChildOfClass("Tool").ToolTip
        image.Image = character:FindFirstChildOfClass("Tool").TextureId
    end
end)

When I run it and pull out a tool, nothing changes. I don't get any errors... Anyone know what I'm doing wrong?

P.S. This is in a LocalScript within the StarterGui.

1 answer

Log in to vote
0
Answered by 7 years ago

It seems that you are trying to edit the GUI elements in StarterGui. The problem is that StarterGui is what is cloned into the player's GUI when they spawn. To fix this, you can use a for loop with the :GetPlayers() function to directly edit the player's GUI.

If you're just trying to edit the GUI of the person who equipped the tool, you can change the frame variable to the location in the player's PlayerGui.

For example:

local frame = player.PlayerGui.ScreenGui.Frame --or whatever

More info here

Ad

Answer this question