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

This script for my UI works in Studio.... Why not in the active place?

Asked by 8 years ago

The script is in Starter GUI > Screen GUI > Script. Text Label is also in Starter GUI > Screen GUI

Here's the script within the UI:

local RunService = game:GetService("RunService")
local Player = game:GetService("Players").LocalPlayer -- Get the player
local Mouse = Player:GetMouse() -- Get the player's mouse

-- Just creating a name tag for this example. This is assuming the script is inside a ScreenGui that's in the PlayerGui.
local Tag = Instance.new("TextLabel",script.Parent)
Tag.Text = ""
Tag.Visible = false
Tag.TextColor3 = Color3.new(0,204,204)
Tag.Font = "ArialBold"
Tag.FontSize = "Size18"
Tag.BackgroundColor3 = Color3.new(0,0,75)
Tag.BackgroundTransparency = 0
Tag.TextXAlignment = "Left"

-- Using the RenderStepped event of RunService, which updates at roughly 1/60th of a second (about twice as fast as the generic wait function, obviously this should still be in a local script)

RunService.RenderStepped:connect(function()
    local Target = Mouse.Target -- Get the object the mouse is hovering over
    if Target then -- Make sure the target exists

        -- Update the information when a target exists
        Tag.Text = Target.Name
        Tag.Size = UDim2.new(0,Tag.TextBounds.X,0,20) -- TextBounds.X will make the tag be as long as the text, giving it a more complimenting appearance
        Tag.Visible = true

    -- If no target exists, then...
    else

        -- Hide the tag
        Tag.Visible = false

    end 

    -- Update the tag's position with the mouse
    Tag.Position = UDim2.new(0,Mouse.X-Tag.AbsoluteSize.X,0,Mouse.Y-Tag.AbsoluteSize.Y)
end)

0
I would change line 18 to a mouse move event. This might be your problem. I couldn't see anything else that could be causing the problem. Using a mouse move event should also be more efficient. User#11440 120 — 8y
0
Change it from a script to a local script. You can only get the players mouse in a local script when the game is running as an active place. Uglypoe 557 — 8y
0
Oh, I though he was using a Local Script but Uglypoe is right. Use a LocalScript! User#11440 120 — 8y

Answer this question