Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Remote event doesn't run the script. How do I fix this?

So I have two remote events in the replicated storage start1 and finish1. I have a local script in the starter pack which has a script inside of it.

Scripts:

Local:

local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local toggle = false
local remoteEvent = game.ReplicatedStorage:WaitForChild("Start1")
local remoteEvent2 = game.ReplicatedStorage:WaitForChild("Finish1")

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q and toggle == false then
		remoteEvent:FireServer()
		toggle = true
	end
end)

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q and toggle == true then
		remoteEvent2:FireServer()
		toggle = false
	end
end)

ServerScript inside the local script:

Debounce = false
Aura1 = game.ReplicatedStorage:WaitForChild("SixPaths1")
Aura2 = game.ReplicatedStorage:WaitForChild("SixPaths2")


game.ReplicatedStorage.Start1.OnServerEvent:Connect(function(player)
	for i = 1,1 do
		for i, v in pairs(player.Character:GetChildren()) do
			Aura1Clone = Aura1:Clone()
			Aura2Clone = Aura2:Clone()
			Aura1Clone.Parent = v
			Aura2Clone.Parent = v
		end
	end
	Pants = player.Character.Pants
	Shirt = player.Character.Shirt
	Shirt.Parent = game.ReplicatedStorage
	Pants.Parent = game.ReplicatedStorage
	
	for i, v in pairs(player.Character:GetChildren()) do
		if v:IsA("BasePart") then 
			v.Material = Enum.Material.Neon
			v.Color = Color3.fromRGB(170,85,0)
		end
	end
	player.Character.Head.Color = Color3.fromRGB(218,133,65)
	player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed*2
	player.Character.Humanoid.MaxHealth = 150
	game.ReplicatedStorage.Handle.Color = Color3.fromRGB(255,89,89)
	game.ReplicatedStorage.RasenExplosion.Color = Color3.fromRGB(255,89,89)
end)

game.ReplicatedStorage.Finish1.OnServerEvent:Connect(function(player)
	Aura1Clone:Destroy()
	Aura2Clone:Destroy()
end)

My problem is that when I press q again it doesn't run the second function like it is supposed to. Do you guys know how to fix this?

1 answer

✓ Accepted answer

As with anything, the perfect way to find the problem is putting prints throughout your code to verify whether or not it is running, and how it is running.

An additional word of advice; you can do toggle = not toggle and an if-elseif statement to condense your client code significantly.

This discussion is preserved as it was. New answers, comments, and votes are closed.