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
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.
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!
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)