#Hello my name is TheOnlySmarts and I am here to explain LUA to you and help you rewrite this script.
Firstly place a part into the Workspace. Now, you are free to name the part whatever you like, whether it be "Chest" or "ClickPart"; it's all up to you!
Then, insert a normal and regular script into the part. After that place a RemoteEvent into ReplicatedStorage and do not change it's name.
Now, place a LocalScript inside of your StarterGui. Name this script Client to define what the script is a part of, which it is a part of the Client.
Now that we have our properties set out, open both scripts and we'll begin working inside the regular script first.
So, we need to lay down some ground rules and define our objects.
local RE = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local C = script.Parent
local CD = Instance.new("ClickDetector")
As you can see I have quoted some of the code to give a better understanding.
Now we'll insert a PlayerAdded function, which runs a following amount of code when a player joins the server.
local RE = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local C = script.Parent
local CD = Instance.new("ClickDetector")
game.Players.PlayerAdded:Connect(function(player)
end)
Good job! Now we have a basic format to begin triggering and creating stuff. Firstly we need to Parent CD and use our RemoteEvent to fire the Client.
local RE = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local C = script.Parent
local CD = Instance.new("ClickDetector")
game.Players.PlayerAdded:Connect(function(player)
CD.Parent = C
CD.MouseClick:Connect(function()
RE:FireClient(player)
end)
end)
Now that we have fired the Client, we are going into our LocalScript("Client") and we're going to run some lines of code to perform something.
local RE = game.ReplicatedStorage:WaitForChild("RemoteEvent")
RE.OnClientEvent:Connect(function(player)
end)
We're going to define our RemoteEvent again because it's a new script, now this time, we will accept the Fire by typing OnClientEvent.
local RE = game.ReplicatedStorage:WaitForChild("RemoteEvent")
RE.OnClientEvent:Connect(function(player)
script.Parent.GUI.Enabled = true
wait(5)
script.Parent.GUI.Enabled = false
end)
Now we have made it when the part is clicked, GUI will become fully visible for 5 seconds, and then it will become invisible.
Of course once you click the Part again, it will keep on going!
#Sincerely, TheOnlySmarts
If you learnt something from me, please click Accept Answer!
1 comment
Why'd you define "gui" twice?