0

# For some reason. My MouseButton1Click script won't even run? Help!

Edited 4 days ago

I'm trying to make a localscript that when the button is pressed. the switch moves to the other side. But i havent even made it to that point! The "Script.Parent.MouseButton1Click:Connect(function()" Isnt working. Its not even firing. I assume one of the variables is making it wait for eternity or something. Or roblox is lagging. But what am I doing wrong?

-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- Script Values
local Mode = "WonderLand"
local CoolDown = false

--Objects
local BackGround = script.Parent.Parent
local Button = script.Parent

local Player = Players.LocalPlayer

local WonderButton = BackGround.WonderLand
local HorridButton = BackGround.HorridLand

--Script

script.Parent.MouseButton1Click:Connect(function() --Not Working
print("Switch Pressed")
if not CoolDown and Mode == "WonderLand" then
CoolDown = true
Mode = "HorridLand"
ReplicatedStorage:FindFirstChild("HorridLand").Parent = game.Workspace
game.Workspace:FindFirstChild("WonderLand").Parent = ReplicatedStorage
Button:TweenPosition(HorridButton.Position)
CoolDown = false
elseif not CoolDown and Mode == "HorridLand" then
CoolDown = true
Mode = "WonderLand"
ReplicatedStorage:FindFirstChild("WonderLand").Parent = game.Workspace
game.Workspace:FindFirstChild("HorridLand").Parent = ReplicatedStorage
Button:TweenPosition(WonderButton.Position)
CoolDown = false
end
end)


0
Might be because it's a local script. Try it in a normal script, remove the Player variable, and instead of "script.Parent.MouseButton1Click:Connect(function()", do "script.Parent.MouseButton1Click:Connect(function(Player)". This gets the Local player. CoolBlueJay000 8 — 4d
0
Oh! I might be wrong here, where it says "if not CoolDown", try "if not CoolDown == true and Mode == WonderLand then".. Sorry if I'm wrong here, I'm a bit new with scripting CoolBlueJay000 8 — 4d
0
*correction: do "if not Cooldown == true" on all of the ones that reference it.* CoolBlueJay000 8 — 4d
0
Nothing has worked. By the way! I know your new so i'll correct you. I dont believe you can edit a gui in a normal script Galaxybombboy 117 — 4d
0
Why would you allocate 'Button', then neglect it with referencing 'script.Parent' directly? ':FindFirstChild()' is not a replacement for the dot operator, you should not be using it in this program. Ziffixture 6529 — 4d
0
It can't just "not work". What is the program type, location, and Instance classification of the Button. Ziffixture 6529 — 4d
0
No worries! I fixed it. I will post how i fixed it later! Galaxybombboy 117 — 3d

0

I highly suggest using

WaitForChild("Ins")


Your object could happen to not load in time, therefore bugs out or something similar.

0

I fixed it!

-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")

-- Script Values
local Mode = "WonderLand"
local CoolDown = false

--Objects
local BackGround = script.Parent.Parent
local Button = script.Parent

local Player = Players.LocalPlayer
local Safe = Player:FindFirstChild("Safe")

local WonderButton = BackGround.WonderLand
local HorridButton = BackGround.HorridLand

--Script

script.Parent.MouseButton1Click:Connect(function()
print("Switch Pressed")
if CoolDown == false and Mode == "WonderLand" then --MAKES IT DARKER AND GOTH
CoolDown = true
Mode = "HorridLand"
Button:TweenPosition(HorridButton.Position, nil, nil, 0.7)
wait(0.7)
ReplicatedStorage:FindFirstChild("HorridLand").Parent = game.Workspace
game.Workspace:FindFirstChild("WonderLand").Parent = ReplicatedStorage
Lighting.ClockTime = 1
wait(0.4)
CoolDown = false
elseif CoolDown == false and Mode == "HorridLand" then -- MAKES IT LESS GOTH
CoolDown = true
Mode = "WonderLand"
Button:TweenPosition(WonderButton.Position, nil, nil, 3.4)
wait(3.4)
ReplicatedStorage:FindFirstChild("WonderLand").Parent = game.Workspace
game.Workspace:FindFirstChild("HorridLand").Parent = ReplicatedStorage
Lighting.ClockTime = 14
wait(0.6)
CoolDown = false
end
end)


Heh.. My error was i was trying to use TweenService for a gui...