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

how do i run touched event on local script?

Asked by 4 years ago
Edited 4 years ago

so im making an easter egg in my game and there is a part that changes text label text But only for the player who touched the brick. Yes the script is in starter gui.

local part = game.Workspace.special.evenmorespecial.secret
part.Touched:Connect(function()
    local text1 = "..."
    local text2 = "why would someone like this come here?"
    local text3 = "hmm?"
    local text4 = "i guess you dont like to talk."
    local text5 = "... or you are a bit shocked?"
    local text6 = "you probably got here by accident... just like i did..."
    local text7 = "well, i didn't see a single human for years!"
    local text8 = "i'll reward you with the ability to spawn the green dirt."
    local text9 = "bye!"
    local text = game.StarterGui.TFlaniganDialogue.d1
    wait(1)
    for i = 1, #text1 do
        text.Text = string.sub(text1, 1, i)
        wait(0.04) 
    end
    wait(3)
    for i = 1, #text2 do
        text.Text = string.sub(text2, 1, i)
        wait(0.04) 
    end
    wait(4)
    for i = 1, #text3 do
        text.Text = string.sub(text3, 1, i)
        wait(0.04)
    end
    wait(3)
    for i = 1, #text4 do
        text.Text = string.sub(text4, 1, i)
        wait(0.04)
    end
    wait(4)
    for i = 1, #text5 do
        text.Text = string.sub(text5, 1, i)
        wait(0.04) 
    end
    wait(3)
    for i = 1, #text6 do
        text.Text = string.sub(text6, 1, i)
        wait(0.04) 
    end
    wait(3)
    for i = 1, #text7 do
        text.Text = string.sub(text7, 1, i)
        wait(0.04) 
    end
    wait(3)
    for i = 1, #text8 do
        text.Text = string.sub(text8, 1, i)
        wait(0.04) 
    end
    wait(4)
    for i = 1, #text9 do
        text.Text = string.sub(text9, 1, i)
        wait(0.04) 
    end
end)

2 answers

Log in to vote
2
Answered by 4 years ago

Well you can put the touched event in a serverscript and use a remote event to fire a signal to the client, then use OnClientEvent to handle the request.

Examples:

-- Server Script
part.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
                local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
                remoteEvent:FireClient(plr)
        end   
end)
-- Client script in startergui
remoteEvent.OnClientEvent:Connect(function()
-- your easter egg code here
end)
0
it says onclientevent can be only used on the client. do i have to do something with local scripts? TFlanigan 86 — 4y
0
For server->client, use `remoteEvent.OnClientEvent` in a localscript(s) and use `remoteEvent:FireClient(player)` or `remoteEvent:FireAllClients()` in a server script. Client->Server should instead use `remoteEvent:FireServer()` in a localscript and use `remoteEvent.OnServerEvent` in server script royaltoe 5144 — 4y
0
article better explaining how it works: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events royaltoe 5144 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

On the same local script do

Local variable = what the local part's name is

If variable.touched:connect(function ()
       Print("or code goes here")
end)

Answer this question