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

The server message button won't work. Anybody know how to improve it?

Asked by 4 years ago

I am making a server message button, but it doesn't seem to work. Anybody know how I can fix this so that it does work? Or any tips?

function onClicked()
    local waittime = 5 --Replace with how long you want the message to last
    local m = Instance.new("Hint")
    m.Parent = game.Workspace
    m.Text = "~TEXT~"
    wait(waittime)
    m:Destroy()

end


0
Do you ever call the function? CeramicTile 847 — 4y
0
Did you call the function??? I need more information on what you're trying to do here. JayShepherdMD 147 — 4y
0
Hint is deprecated. With the introduction of Roblox’s GUI features hints have been deprecated and TextLabels should be used instead for new work. The TextLabel object offers a wide range of features for displaying and customizing text that hints do not. User#30567 0 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago
local clickdetect = Instance.new("ClickDetector") -- Creates the clickdetector
clickdetect.Parent = script.Parent -- assigns the clickdetector's parent to the part
if script.Parent:FindFirstChild("ClickDetector") then -- makes sure the clickdetector is inside of the part
function onClicked(person) -- the function
    local waittime = 5 --Replace with how long you want the message to last
    local m = Instance.new("Hint") -- Creates the hint
    m.Parent = game.Workspace -- assigns the hint's parent to workspace
    m.Text = (person.Name .." Has Clicked The ".. script.Parent.Name) -- what you want the hint to say
    wait(waittime) -- how long it takes to destroy the hint, this is changed in 'line 6' of the script
    m:Destroy() -- destroys the hint
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked) -- This is an event, to call the function.
end

You didn't call the function, and I don't know if you already had clickdetector inside of your part so I just added it for you.

0
FearlessX96, your solution doesn't seem to work. I don't know what I did wrong, but typed exactly what you had. Maybe it has to do with line 8? satrasatra 8 — 4y
0
Nothing wrong with line 8. First, copy and paste the script into your script then drag the script and place it inside the block you want to click. Then test it on Roblox Studio and try clicking the block. FearlessX96 74 — 4y
Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago

Problems that wrong:

You did wrong some problems. Firstly, yep, I think everyone knows, you WASN'T CALL THE FUNCTION.

Second, @TTChaos have already commented at your question, 'Hint' is deprecated and you should use TextLabel.

Third, as important, you need "ClickDetector". That will fire an event called 'MouseClick' when you clicked.

The way to fix the problems:

You must delete the line 3. 'Hint' is deprecated, and enter a "ClickDetector" inside the part. And insert a "TextLabel" into the StarterGui.ScreenGui (You don't need to change any names.)

Script:

local click = script.Parent.ClickDetector

function OnClicked(plr)
    local wait-time = 5
    local text = game.StarterGui.ScreenGui.TextLabel

    text.Visible = true
    text.Text = "~TEXT~"
    print(plr.Name .. "had clicked the part!")
    print("Waiting for 5 seconds...")
    wait(wait-time)
    print("Done!")
    text.Visible = false
end

click.MouseClick:Connect(OnClicked)

If you have any questions, comment below! I'll be happy to answer them :) If this answer helped you, mark this as the answer! :3 Bye!

0
What do you mean by add a textlabel? If I only add a text label, it won't appear. satrasatra 8 — 4y
0
Go to StarterGui and insert a ScreenGui and put the TextLabel inside, this might work. Xapelize 2658 — 4y
Log in to vote
0
Answered by 4 years ago

I actually figured it out myself, this is the code I used.

function onClicked()
    local m = Instance.new("Message")   
    m.Parent = game.Workspace       
    m.Text = "Text"         
    wait(5)
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

Answer this question