Hello! I am having trouble on this script I am working on. I am trying to make a button when upon clicked, it moves a model from ServerStorage to workspace.
function onClicked() game.Lighting[COMP]:Clone() = game.Workspace end script.Parent.ClickDetector.MouseClick:connect(onClicked)`
I understand this is probably dead wrong. Can someone help me point out my mistake and help me with my question?
Thanks!
Try this:
script.Parent.ClickDetector.MouseClick:connect(function() game.ServerStorage.COMP:Clone().Parent = workspace -- This way you only use 1 line. end)
You could also do this:
local serverstorage = game:GetService("ServerStorage") script.Parent.ClickDetector.MouseClick:connect(function() serverstorage.COMP:Clone().Parent = workspace end)
If I was you it would depend on what I was doing. If I only needed to do a simple script with a few lines 20 max I would use the first method. If it was a script with hundreds of lines I would go with the second way. Mainly because of the variable. The variable lets me access server storage with just one word.
script.Parent.ClickDetector.MouseClick:Connect(function(player) local clone = game:GetService("ServerStorage")[COMP]:Clone() clone.Parent = workspace end)