Having problem with my script disabling script!

Hello!
So I’m having a problem with my script… it is not working for some reason.
I didn’t find anything anywhere how do fix it

The script should change the text to on and false when clicked on a button and then make the script disabled when the text says off and enabled when the text is on.

Here is the script:

local falldamage = game.ServerScriptService:WaitForChild("FallDamage")
local impact = falldamage:FindFirstChild("Impact")

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Text == "Fall damage: On" then
		script.Parent.Text = "Fall damage: False"
		impact.Disabled = false
	else
		script.Parent.Text = "Fall damage: On"
		impact.Disabled = true
	end
end)
2 Likes

It seems like you’re detecting MouseEvents on a gui from a serverscript. Mouse events only fire on the client, meaning the serverscript will never register that the button was clicked. Switch to a localscript and use a RemoteEvent.

2 Likes

I am using a local script and how would I use a remote event on it?

2 Likes

localscript:

local RemoteEvent = game.ReplicatedStorage.RemoteEvent--Change to where it is
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Text == "Fall damage: On" then
script.Parent.Text = "Fall Damage: False"
RemoteEvent:FireServer(true)
else
script.Parent.Text = "Fall Damage: On"
RemoteEvent:FireServer(false)
end)

ServerScript:

Local RemoteEvent = game.ReplicatedStorage.RemoteEvent--Change to where it is
local falldamage = game.ServerScriptService:WaitForChild("FallDamage")
local impact = falldamage:FindFirstChild("Impact")

RemoteEvent.OnServerEvent:Connect(function(bool)
impact.Disabled = bool
end)

How it works:
when our local player presses the button the localscript is parented to, it will fire the remote event and pass to the server script a boolean to determine if it should be enabled or disabled,
the server then receives these values, the disabled property of the impact gets set to the passed boolean value!

Well I tried it but it didn’t work… and I didn’t get any errors too…

1 Like

is impact the script which contains the fall damage?
because if not then the script would have to disable the script which damages the player

yes
image

2 Likes

WAIT I GOT IT, the script checks for the string “Fall damage: On”
but in the else it changes it to “Fall Damage: On”
the strings have to match
change capital D from damage to d

I did… now I can click on it and everytime it changes the text… before it just stopped at false.
but it still dosent disable the impact script. Maybe you cant disable scripts in game?
or can you?

well i know you can because i’ve done it before…
maybe add a print in the event to check if it actually runs

weird… everything works fine in both scripts

okay so i’ve tried it in my own project and i had an empty script called todo for this (yes my todo list hehe)

and i found a few that could cause this so i fixed them
just copy this structure:

local RemoteEvent = game.ReplicatedStorage.RemoteEvent--Change to where it is
script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Text == "Fall Damage: On" then
		script.Parent.Text = "Fall Damage: False"
		RemoteEvent:FireServer(game.Players.LocalPlayer,true)--The server also apparently requires a player value
	else
		script.Parent.Text = "Fall Damage: On"
		RemoteEvent:FireServer(game.Players.LocalPlayer,false)
	end--forgor an end hihi
end)

server

local R = game.ReplicatedStorage.RemoteEvent

R.OnServerEvent:Connect(function(plr,bool)
	workspace.ToDo.Disabled = bool--Change this to your script, so impact and falldamage
end)

hmm still not working… but wait could the script called falldamage cause this?
cuz that script enables the impact when player has added

okay i found them and it works for me now
server

local R = game.ReplicatedStorage.RemoteEvent

R.OnServerEvent:Connect(function(plr,bool)
	print("ran")
	print(bool)
	workspace.ToDo.Disabled = bool
end)

local:

local RemoteEvent = game.ReplicatedStorage.RemoteEvent--Change to where it is
local IsOn = true
script.Parent.Activated:Connect(function()
	if IsOn then
		script.Parent.Text = "Fall Damage: False"
		IsOn = false
		print(IsOn)
		RemoteEvent:FireServer(IsOn)
	else
		script.Parent.Text = "Fall Damage: On"
		IsOn = true
		print(IsOn)
		RemoteEvent:FireServer(IsOn)
	end
end)

i did this right on time, but i need to go now goodluck !
prints werer for checking

2 Likes

You can’t view ServerScriptService or ServerStorage from the client, so the variable falldamage would always be nil. Same with variable impact since it looks inside falldamage which we already know is nil. You will need to add RemoteEvents to this to make it function correctly.

1 Like

well I got it work ty, yay lol

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.