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

Change Text of Gui for everyone when a player clicked ClickDetector and fired RemoteEvent? [Solved]

Asked by
Dleppyy 41
5 years ago
Edited 5 years ago

Hi, I'm trying to figure out how to make a text change for everyone when a player has clicked a certain click detector. I'm assuming I need to use FireAllClients() but I'm not sure how to do it as I've never used it before. I also tried looking on the wiki, but couldn't find anything. If anyone could have that'll be great.

The script in the ClickDetector

local RepStorage = game:GetService("ReplicatedStorage")
local OpenN = RepStorage:WaitForChild("OpenNote")
local CD = game.Workspace.Cave.Bench.Paper.paper

local function clicked()
    OpenN:FireServer()
end

CD.ClickDetector.MouseClick:Connect(clicked) 

The script in ServerScriptService


local CD = game.Workspace.Cave.Bench.Paper.paper.ClickDetector local Time = 0.08 game.ReplicatedStorage.OpenNote.OnServerEvent:Connect(function(player) local StartingText = player.PlayerGui.StoryLine.PostCrashText.Text local Task = player.PlayerGui.StoryLine.PostCrashText.Task.Desc local TaskFrame =player .PlayerGui.StoryLine.PostCrashText.Task local Paper = game.Workspace.Cave.Bench.Paper.paper local PaperDecal = game.Workspace.Cave.Bench.Paper.paper.Decal -- // Player Found Note \\ -- CD:Remove() Paper.Transparency = 1 PaperDecal.Transparency = 1 Task.Text = " " StartingText.Text = " ".. player.Name wait(Time) StartingText.Text = " ".. player.Name.." h" wait(Time) StartingText.Text = " ".. player.Name.." ha" wait(Time) StartingText.Text = " ".. player.Name.." has" wait(Time) StartingText.Text = " ".. player.Name.." has f" wait(Time) StartingText.Text = " ".. player.Name.." has fo" wait(Time) StartingText.Text = " ".. player.Name.." has fou" wait(Time) StartingText.Text = " ".. player.Name.." has foun" wait(Time) StartingText.Text = " ".. player.Name.." has found" wait(Time) StartingText.Text = " ".. player.Name.." has found a" wait(Time) StartingText.Text = " ".. player.Name.." has found a n" wait(Time) StartingText.Text = " ".. player.Name.." has found a no" wait(Time) StartingText.Text = " ".. player.Name.." has found a not" wait(Time) StartingText.Text = " ".. player.Name.." has found a note" wait(Time) StartingText.Text = " ".. player.Name.." has found a note!"

1 answer

Log in to vote
0
Answered by 5 years ago

Put this in a script in the workspace:

local click = workspace.Click:WaitForChild("ClickDetector")
local Player = game.ReplicatedStorage:WaitForChild("Player")

game.Players.PlayerAdded:Connect(function(player)
    local ScreenGui = Instance.new("ScreenGui",player.PlayerGui)
    local Text = Instance.new("TextLabel",ScreenGui)
    Text.Name = "TextLabel"
    Text.Position = UDim2.new(0.5, 0,0.75, 0)
    Text.Size = UDim2.new(0.75, 0,0.25, 0)
    Text.AnchorPoint = Vector2.new(0.5, 0.5)
    Text.Font = Enum.Font.Fantasy
    Text.TextScaled = true
    Text.TextWrapped = true
    Text.Text = "Search the paper"

    click.MouseClick:Connect(function(player)
       Player:FireAllClients(player.Name)
       click:Destroy()
    end)
end)

put this in a modulescript in the ReplicatedStorage and name it "TypeWriter":

local SOURCE_LOCALE = "en"

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

local player = Players.LocalPlayer

local translator = nil
pcall(function()
    translator = LocalizationService:GetTranslatorForPlayerAsync(player)
end)
if not translator then
    pcall(function()
        translator = LocalizationService:GetTranslatorForLocaleAsync(SOURCE_LOCALE)
    end)
end

local TypeWriter = {}

local defaultConfigurations = {
    delayTime = 0.2,
    extraDelayOnSpace = true
}

function TypeWriter.configure(configurations)
    for key, value in pairs(defaultConfigurations) do
        local newValue = configurations[key]
        if newValue ~= nil then
            defaultConfigurations[key] = newValue
        else
            warn(key .. " is not a valid configuration for TypeWriter module")
        end
    end
end

function TypeWriter.typeWrite(guiObject, text)
    guiObject.AutoLocalize = false
    guiObject.Text = ""
    local displayText = text
    if translator then
        displayText = translator:Translate(guiObject, text)
    end
    for first, last in utf8.graphemes(displayText) do
        local grapheme = string.sub(displayText, first, last)
        guiObject.Text = guiObject.Text .. grapheme
        if defaultConfigurations.extraDelayOnSpace and grapheme == " " then
            wait(defaultConfigurations.delayTime)
        end
        wait(defaultConfigurations.delayTime)
    end
end

return TypeWriter

then place this in a localscript in the StarterGui with Parent StarterGui:

-- services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Player  = game.Players.LocalPlayer
local PlayerName = game.ReplicatedStorage.Player

-- Require module
local Player = Istance.new("RemoteEvent", game.ReplicatedStorage)
Player.Name = "Player"
game.ReplicatedStorage.Player.OnClientEvent:Connect(function(TheChosen)
    print(TheChosen)
    if TheChosen == Player.Name then
        local TypeWriter = require(ReplicatedStorage:WaitForChild("TypeWriter"))
        TypeWriter.typeWrite(Player.PlayerGui.ScreenGui.TextLabel, "You found it")
    else
        local TypeWriter = require(ReplicatedStorage:WaitForChild("TypeWriter"))
        TypeWriter.typeWrite(Player.PlayerGui.ScreenGui.TextLabel, TheChosen.."found it")
    end
end)

Test this in a empty place/baseplate. If it works, you can adapt it.

0
thanks Dleppyy 41 — 5y
0
If this helped you ??? Eternalove_fan32 188 — 5y
0
i didn't use this script, but i used part of it to make my own script Dleppyy 41 — 5y
0
ok Eternalove_fan32 188 — 5y
0
thanks though Dleppyy 41 — 5y
Ad

Answer this question