Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer
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

10 comments

0

Thank you, I accidentally deleted it and never noticed. :L

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.

0

You indeed have. LocalScripts won't run in Workspace. You probably want to put the ScreenGui inside StarterGui instead.

0

I put the screengui inside startergui, it still isn't showing up

0

See my edited answer. Sorry for the delay.

0

It still isn't working, I gave you access via team create, don't destroy the whole thing ok :)

0

I'm going to change it to be a surface gui that makes the PersonalTV on click

0

Instead I'm doing a screen gui

0

I'm starting a new question, that feels appropriate

This discussion is preserved as it was. New answers, comments, and votes are closed.