Script sometimes works and sometimes doesn't

Hey everyone, experiencing a very odd issue with these scripts and would love some help with it.

Server script:

StartRE=game.ReplicatedStorage.Start.Start
Start=script.Parent
Start.ClickDetector.MouseClick:Connect(function(plr)
	StartRE:FireClient(plr, Start)
end)

Local script inside GUI:

Player=game:GetService("Players").LocalPlayer
GUI=script.Parent.TextLabel
StartRE=game.ReplicatedStorage.Start.Start
function Start(Start)
	local Count=0
	Start.SurfaceGui.TextLabel.Text=3
	wait(1)
	Start.SurfaceGui.TextLabel.Text=2
	wait(1)
	Start.SurfaceGui.TextLabel.Text=1
	wait(1)
	Start.SurfaceGui.TextLabel.Text=("")
	Start.CanCollide=false
	Start.Transparency=1
	Start.ClickDetector.MaxActivationDistance=0
	while Start.Parent.Value.Value==false do
		wait(0.1)
		Count=Count+1
		GUI.Text=(Count/10)
		print("hi")
	end
	Start.CanCollide=true
	Start.Transparency=0
	Start.ClickDetector.MaxActivationDistance=32
	Start.Parent.Value.Value=false
end
StartRE.OnClientEvent:Connect(Start)

Another local script inside GUI:

Player=game:GetService("Players").LocalPlayer
StopRE=game.ReplicatedStorage.Start.End
StopRE.OnClientEvent:Connect(function(Value)
	game.Workspace.Obby1.Value.Value=true
end)

Now, these scripts always work fine the first time I run them, but after that, the second script I listed will sometimes only run up to line 12 and then won’t finish the iteration for whatever reason, but it never throws an error, and it will then work if I fire the event again. I have absolutely no idea why this is happening and would love some insight. Thanks :slight_smile:

6 Likes

Honestly, I’m having a similar issue. For the past few days I’ve noticed client-sided code only works sometimes. Despite the fact that I didn’t change anything. Roblox has been having issues lately, it could be related but I’m not sure.

3 Likes

hmmm yea maybe. I’ve been racking my brain over this for hours and really have no clue what’s happening.

I’ve noticed this started happening since I updated studio. Out of curiosity are you using macOS or Windows? I’m on macOs so sometimes it takes a little longer for Roblox staff to straighten out bugs that come with updates.

2 Likes

I’m on windows, but I did just update studio today and I’ve only just started having this issue, so it might be something to do with the update?

2 Likes

If you said that the 12nd line of your script is this line

Start.SurfaceGui.TextLabel.Text=("")

Then try this instead?

Start.SurfaceGui.TextLabel.Text=3
	task.delay(1,function()
	   Start.SurfaceGui.TextLabel.Text=2
	   task.delay(1,function()
	      Start.SurfaceGui.TextLabel.Text=1
	      task.delay(1,function()
	      Start.SurfaceGui.TextLabel.Text=(" ") -- i added a space in the "" just in case
	      Start.CanCollide=false
	      Start.Transparency=1
	      Start.ClickDetector.MaxActivationDistance=0
	      while Start.Parent.Value.Value==false do
	          	wait(0.1)
	           Count=Count+1
		   GUI.Text=(Count/10)
		   print("hi")
   	   end
   	   Start.CanCollide=true
	   Start.Transparency=0
	   Start.ClickDetector.MaxActivationDistance=32
	   Start.Parent.Value.Value=false
      end)
   end)
end)
--  i may miss something in this scirpt because i didn't script in roblox studio btw

Also recently, i don’t find much of a errors that occur in my cilent script, probably because something went wrong with your script or it’s just too soon for me to find it :cold_sweat:

2 Likes

Tried this and had the same issue. it works like 70% of the time despite the fact that literally nothing changes :confused:
Thanks a lot for putting the time into writing this though :slight_smile:

2 Likes

Is the script doesn’t run after this line

Start.SurfaceGui.TextLabel.Text=(" ")

or it doesn’t run that line but the rest beside the line is running normally

These are the lines that don’t run

   Start.CanCollide=false
	Start.Transparency=1
	Start.ClickDetector.MaxActivationDistance=0
	while Start.Parent.Value.Value==false do
		wait(0.1)
		Count=Count+1
		GUI.Text=(Count/10)
		print("hi")
	end
	Start.CanCollide=true
	Start.Transparency=0
	Start.ClickDetector.MaxActivationDistance=32
	Start.Parent.Value.Value=false

Everything before that always runs, but yea, about 30% of the time, all of that doesnt run.

I tried putting

print(Start.CanCollide)

after

Start.CanCollide=false

And it printed false, but in the workspace it still showed as true, and I still couldnt walk through the part. It’s like the script can see what’s happening, but the client can’t which doesn’t make sense since the script is running on the client blaargghhhh

Wait, is this local script inside the part?

1 Like

No, this is a local script inside of the GUI referenced with

GUI=script.Parent.TextLabel

The GUI is in starter GUI, so it is the right place for a local script to be running right?

The part is parsed as the argument “Start” in the remote event called “StartRE”

2 Likes

Yes, only if the gui is inside player’s StarterGui which will work as a cilent and if it’s a descendant of another part which is not a players will not occur because the cilent doesn’t do anything to server.

So if the gui is a descendant of a model that is not a player, the script won’t work.

2 Likes

If you’re changing that on the client, I don’t think it will replicate to the server.

I don’t want it to replicate to the server. It works as intended most of the time. But sometimes it doesn’t and i have no idea why.

2 Likes

I just noticed that your script change the CanCollide twice

   Start.CanCollide=false -- here
	Start.Transparency=1
	Start.ClickDetector.MaxActivationDistance=0
	while Start.Parent.Value.Value==false do
		wait(0.1)
		Count=Count+1
		GUI.Text=(Count/10)
		print("hi")
	end
	Start.CanCollide=true -- here
	Start.Transparency=0
	Start.ClickDetector.MaxActivationDistance=32
	Start.Parent.Value.Value=false

Which will only set the part canCollide to true
So aftter setting the part CanCollide to false
Do this instead :

   Start.CanCollide=false
	Start.Transparency=1
	Start.ClickDetector.MaxActivationDistance=0
	while Start.Parent.Value.Value==false do
		wait(0.1)
		Count=Count+1
		GUI.Text=(Count/10)
		print("hi")
	end
    task.delay(1,function() -- change how long you want it to start canCollide = false
	    Start.CanCollide=true
	    Start.Transparency=0
	    Start.ClickDetector.MaxActivationDistance=32
	    Start.Parent.Value.Value=false
    end)
1 Like

I will try this and get back to you, but the idea is that when the value of “Start.Parent.Value” is set to true (by a different local script) the while loop is broken and the parts cancollide is instantly set to true. So I don’t see what your code will change other than adding the 1 second delay

1 Like

not really sure what you need help with but the LocalScript could look a bit better

-- learn to add 'local' and spaces between variable names
local Player = game:GetService("Players").LocalPlayer
local TextLabel = script.Parent.TextLabel -- the textlabel isn't your gui
local StartRE = game.ReplicatedStorage.Start.Start -- rename 'Start' to avoid repitition

local function Start(Start)
	local StartLabel = Start.SurfaceGui.TextLabel -- make a variable for easier reuse

    -- use a for loop instead of counting down manually
	for i = 3, 1, -1 do
	  StartLabel.Text = i
	  task.wait(1)
    end

	StartLabel.Text = ""
	Start.CanCollide = false
	Start.Transparency = 1
	Start.ClickDetector.MaxActivationDistance = 0

	local Count = 0
	repeat
		task.wait(0.1)
		Count += 1
		TextLabel.Text=(Count/10)
		print("0.1 sec") -- prints should make more sense
    until Start.Parent.Value.Value -- rename 'Value' to avoid repitition

	Start.CanCollide = true
	Start.Transparency = 0
	Start.ClickDetector.MaxActivationDistance = 32
	Start.Parent.Value.Value = false
end

StartRE.OnClientEvent:Connect(Start)
3 Likes

Haha yea your right, my code was a mess and this looks a lot better. Thanks for this.

Also, I had no idea that’s how until works. I originally tried using until but I wrote it like it was a while loop :sob:

sidenote: The print statement was only there when I was troubleshooting, forgot to remove it :PP

2 Likes

Ok buddy listen up. I don’t know what kind of witchcraft or black magic it is but somehow you fixed it and I really can’t figure out why this works and mine doesn’t. Fair enough. Thank you.

2 Likes

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