So far, when I click the part (the 'door') the screen flashes as I ask it to. However, I want the text to appear afterwards for two seconds. Anybody know what mistakes I have made here? Answers would be greatly appreciated.
-- VARIABLES -- colcor = game.Lighting.ColorCorrection local can = script.Parent.Parent.can can = true local replicatedstorage = game.ReplicatedStorage local text = replicatedstorage.TextLabel local textclone = text:Clone() -- USER CLICKS ON DOOR -- script.Parent.MouseClick:connect(function() if can == true then can = false colcor.Brightness = -0.6 wait(.4) colcor.Brightness = 0.6 wait(.4) colcor.Brightness = -0.6 wait(.4) colcor.Brightness = 0.6 wait(.4) colcor.Brightness = -0.2 wait(.4) textclone.Parent = game.StarterGui["DOOR PROMPT"] textclone.Visible = true wait(2) textclone:Destroy() can = true end end)
You are not supposed to clone it to the StarterGui, but actually the PlayerGui. The PlayerGui is located in game.Players.PLAYERNAME.PlayerGui
So. After talking via the community chat, I know how to solve the issues. Here's how you solve it. GUIs are LocalScripts because (if using StarterGui) they immediately replicated to the LocalPlayer.PlayerGui
. A way to solve that is to use Remote Events. There is nothing wrong here apart from some inefficient methods. Also do not use a value, use a variable.
Server Script
colcor = game.Lighting.ColorCorrection local debounce = false --Put a better name rather than 'can'. can = true local remoteEvent = game.ReplicatedStorage.RemoteEvent script.Parent.MouseClick:Connect(function(click) if debounce then --Alternative: if debounce == true debounce = true colcor.Brightness = -0.6 wait(.4) colcor.Brightness = 0.6 wait(.4) colcor.Brightness = -0.6 wait(.4) colcor.Brightness = 0.6 wait(.4) colcor.Brightness = -0.2 wait(.4) remoteEvent:FireClient(game.Players:GetPlayerFromCharacter(click)) debounce = false end end)
Local Script
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function() local plrGui = game.Players.LocalPlayer.PlayerGui plrGui["DOOR PROMPT"].TextLabel.Visible = true end)
(Minor Nitpicks: Do not use connect
as it is deprecated. Use Connect
instead.)