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

How do I make a custom hint module and how do I make the hint show to everybody at the same time?

Asked by 3 years ago

I want to make a better version of the roblox classic, "Hint" class by turning it into an open source module script which will soon contain customisable settings like color, font, animation type, animation speed, etc. And that's my idea of I want it to be in the near future.

Basically, how do I make this serversided or something?

I don't know how to do this in a module script because If I use remote events, it's obviously not going to work, server's never handle GUI's and will fail because of that, so only the client can handle GUI's.

Module located at game.StarterGui

local HintModule = {}

HintModule.Show = function(player, text, delayTime, everyone)
    if everyone == true then
        local guiClone = script:FindFirstChild("ScreenGui"):Clome()

        -- help how do I make this clone and show text to everybody at the same time??
    else
        if not player then return end

        if player then
            script:FindFirstChild("ScreenGui"):Clone().Parent = player.PlayerGui

            player.PlayerGui:FindFirstChild("ScreenGui").Frame.Visible = true

            player.PlayerGui:FindFirstChild("ScreenGui").Frame.TextLabel.Text = text
            task.wait(delayTime)
            player.PlayerGui:FindFirstChild("ScreenGui"):Destroy()
        end
    end
end

return HintModule

The script that calls the module is a local script in the same parent as the module script is.

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

What you need to do is create a server script which will send message to all the clients to show a hint, good reason why you don't do that on client is because an exploiter could send signals to the server and to all other clients which would be no good. When client receives a message to show the hint, he will show it, you can change which client to send the hint to. RemoteEvent.FireAllClients is a function that you can use here, an example:

ServerScriptService.HintSender (Script)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- You can create the remote event in edit mode in studio
local sendHint = Instance.new("RemoteEvent")
sendHint.Name = "SendHint"
sendHint.Parent = ReplicatedStorage

-- Send a hint to a single player after 5 seconds he joins the game
Players.PlayerAdded:Connect(function(player)
    task.wait(5)
    sendHint:FireClient(player, "Sadly you have joined the game", 5)
end)

-- Sends a hint to all players every 5 seconds
while true do
    task.wait(5)
    sendHint:FireAllClients("Hedreon is noob", 2)
end

StarterGui.HintCreator (LocalScript)

This script will listen to remote event signals from the server and tell HintModule to create hints.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local HintModule = require(script.Parent:WaitForChild("HintModule"))

local localPlayer = Players.LocalPlayer

ReplicatedStorage.SendHint.OnClientEvent:Connect(function(text, delayTime)
    HintModule.Show(Players.LocalPlayer, text, delayTime)
end)

StarterGui.HintModule (ModuleScript)

local HintModule = {}

HintModule.Show = function(player, text, delayTime)
    if not player then return end

    -- This if statement is useless since on line earlier you "return" from
    -- the function which stops the function, you can be sure that if
    -- the function continues running then the player exists
    --if player then

    -- Instead of repeating player.PlayerGui:FindFirstChild("ScreenGui")
    -- just save the gui into a variable
    local screenGui = script.ScreenGui:Clone()
    screenGui.Frame.Visible = true
    screenGui.Frame.TextLabel.Text = text
    screenGui.Parent = player.PlayerGui

    task.wait(delayTime)
    screenGui:Destroy()
    --end
end

return HintModule
0
Yes, you are right, I AM a noob scripter indeed, just like from my profile bio in ScriptingHelpers. User#39895 0 — 3y
0
Okay, I just found somerthing, for some reason, not referencing the player when calling "SendHint" or "ShowHint" will not work, I'll try doing something about this. User#39895 0 — 3y
0
It does work, but it doesn't show to everybody at the same time & already I broke the regeneration script, so the entirety of this thing doesn't work anymore. I give up. I shouldn't jump into a massive module script project way too quickly. I need to do simple things first and THEN I will be able to do this myself. User#39895 0 — 3y
0
don't give up noob, I had mistake in my answer, LocalScript should have passed the player parameter to the module, I edited my answer, see if it works now. imKirda 4491 — 3y
0
damn I haven't responded to this in a long, long time User#39895 0 — 2y
Ad

Answer this question