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

How do you do a client event when you touch a brick?

Asked by
jtp40 7
8 years ago

I want to trigger a client event when a brick is touched, I don't know what I'm doing wrong.

Server script inside server script service

game.Players:connect(function(player)
    local event = Instance.new("RemoteEvent")
    event.Parent = player
    event.Name = "MyClientEvent"
    if game.Workspace.PTV.Touched then
        event:FireClient(player)
    end
end)

Local script inside game.Workspace.PTV.ScreenGUI. PTV is a part.

game.Players.LocalPlayer:WaitForChild("MyClientEvent").OnClientEvent:connect(function()
local function PersonalTV() --My only question is how I want the event to be triggered and how I want this part to run when it is triggered, correcting me on this part is not necessary.
    local imageLabel = Instance.new("ImageLabel")
    imageLabel = script.Parent
    imageLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
    imageLabel.Position = UDim2.new(1, 0, 1, 0)
    imageLabel.Image = "rbxassetid://99995960"
    local sound = Instance.new("Sound")
    sound = "rbxassetid://198460934"
    sound:Play()
    wait(41.613)
    sound:Stop()
    wait(0.01)
    imageLabel.Image = "rbxassetid://36169651"
    sound = "rbxasssetid://223103466"
    sound:Play()
    wait(5)
    sound:Stop()
    wait(0.01)
    imageLabel.Image = "rbxassetid://84899195"
    sound = "rbxassetid://374355709"
    sound:Play()
    wait(53.237)
    sound:Stop()
    wait(0.01)
    imageLabel.Image = "rbxassetid://36169651"
    sound = "rbxasssetid://223103466"
    sound:Play()
    wait(5)
    sound:Stop()
    wait(0.01)
end
end)

Edit 1: I want a gui button instead that doesn't use a client event. StarterGui.ScreenGui.TextButton.RageQuitScript

local button = script.Parent
button:WaitForChild("Sound")

local function onButtonClick()

    local imageLabel = Instance.new("ImageLabel")

    imageLabel.Parent = script.Parent

    imageLabel.Size = UDim2.new(0.25, 0, 0.25, 0)

    imageLabel.Position = UDim2.new(0, 0, 0, 0)

    imageLabel.Image = "rbxassetid://99995960"

    local sound = Instance.new("Sound")

    sound = "rbxassetid://198460934"

    sound:Play()

    wait(41.613)

    sound:Stop()

    wait(0.01)

    imageLabel.Image = "rbxassetid://36169651"

    sound = "rbxasssetid://223103466"

    sound:Play()

    wait(5)

    sound:Stop()

    wait(0.01)

    imageLabel.Image = "rbxassetid://84899195"

    sound = "rbxassetid://374355709"

    sound:Play()

    wait(53.237)

    sound:Stop()

    wait(0.01)

    imageLabel.Image = "rbxassetid://36169651"

    sound = "rbxasssetid://223103466"

    sound:Play()

    wait(5)

    sound:Stop()

    wait(0.01)

end
button.MouseButton1Click:connect(onButtonClick)

It isn't working, there is no error message.

1 answer

Log in to vote
0
Answered by
gskw 1046 Moderation Voter
8 years ago
game.Players.PlayerAdded:connect(function(player) -- You missed "PlayerAdded"!
    local event = Instance.new("RemoteEvent")
    event.Name = "MyClientEvent" -- Moved this before .Parent in case :WaitForChild depends on ChildAdded
    event.Parent = player
    if game.Workspace.PTV.Touched then
        event:FireClient(player)
    end
end)
game.Players.LocalPlayer:WaitForChild("MyClientEvent").OnClientEvent:connect(function()
local function PersonalTV() --My only question is how I want the event to be triggered and how I want this part to run when it is triggered, correcting me on this part is not necessary.
    local imageLabel = Instance.new("ImageLabel")
    imageLabel.Parent = script.Parent -- You missed ".Parent" after imageLabel
    imageLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
    imageLabel.Position = UDim2.new(1, 0, 1, 0)
    imageLabel.Image = "rbxassetid://99995960"
    local sound = Instance.new("Sound")
    sound = "rbxassetid://198460934"
    sound:Play()
    wait(41.613)
    sound:Stop()
    wait(0.01)
    imageLabel.Image = "rbxassetid://36169651"
    sound = "rbxasssetid://223103466"
    sound:Play()
    wait(5)
    sound:Stop()
    wait(0.01)
    imageLabel.Image = "rbxassetid://84899195"
    sound = "rbxassetid://374355709"
    sound:Play()
    wait(53.237)
    sound:Stop()
    wait(0.01)
    imageLabel.Image = "rbxassetid://36169651"
    sound = "rbxasssetid://223103466"
    sound:Play()
    wait(5)
    sound:Stop()
    wait(0.01)
end
end)

http://wiki.roblox.com/index.php?title=API:Class/Players/PlayerAdded

0
Thank you, I accidentally deleted it and never noticed. :L jtp40 7 — 8y
0
The gui still isn't showing up, I added a print function and it still isn't showing up either. I might have placed the local script in the wrong place. jtp40 7 — 8y
0
You indeed have. LocalScripts won't run in Workspace. You probably want to put the ScreenGui inside StarterGui instead. gskw 1046 — 8y
0
I put the screengui inside startergui, it still isn't showing up jtp40 7 — 8y
View all comments (6 more)
0
See my edited answer. Sorry for the delay. gskw 1046 — 8y
0
It still isn't working, I gave you access via team create, don't destroy the whole thing ok :) jtp40 7 — 8y
0
I'm going to change it to be a surface gui that makes the PersonalTV on click jtp40 7 — 8y
0
Instead I'm doing a screen gui jtp40 7 — 8y
0
I'm starting a new question, that feels appropriate jtp40 7 — 8y
Ad

Answer this question