✓ Accepted answer
As implied with echobloxia's comment, there is no event connected to the function, meaning there's no listeners for a click. I can't tell if this is a GUI button or a ClickDetector object that is a child of a part, and even though the process is practically the same, I'll include both ways to keep it as unambiguous as possible.
local clickEvent = script.Parent.Parent.Parent.Parent.Parent
clickEvent.MouseButton1Click:Connect(function()
local event = math.random(1, 3)
print(event)
if event == 1 then
local Obby = game.ServerStorage.Obby:Clone()
Obby.Parent = workspace
Obby.delete.Disabled = false
elseif event == 2 then
local LavaSpinner = game.ServerStorage.LavaSpinner:Clone()
LavaSpinner.Parent = workspace
LavaSpinner.delete.Disabled = false
end
end)
This next script assumes your original script is placed inside of a clickable gui button
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:WaitForChild("RemoteEvent")
local button = script.Parent.Parent.Parent.Parent.Parent
button.MouseButton1Click:Connect(function()
local event = math.random(1, 3)
print(event)
event:FireServer(event)
end)
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:WaitForChild("RemoteEvent")
event.OnServerEvent:Connect(function(plr, event)
if event == 1 then
local Obby = game.ServerStorage.Obby:Clone()
Obby.Parent = workspace
Obby.delete.Disabled = false
elseif event == 2 then
local LavaSpinner = game.ServerStorage.LavaSpinner:Clone()
LavaSpinner.Parent = workspace
LavaSpinner.delete.Disabled = false
end
end)
Feel free to discard comments
2 comments
What event are you connecting to the function?
No event. just making it so you can click it