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.
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