LocalScript does half the things I want it to

Hey, so basically I have this LocalScript that’s based on a .Touched event that, when the part is touched, will only do about half the things in the script. For example, it will destroy the doors but won’t make the tppart touchable. What’s weird is that it used to work but now it’s just broken out of nowhere. Nothing is in the output, and it is printing “why???” at the end. Can I get some help?

Sidenote: I get that having so much WaitForChild:'s is bad, but sometimes my code whether it be this script or another doesn’t work without the WaitForChild:'s, so sorry for the spam of it.

local f3part = game.Workspace:WaitForChild("F3Part")
local invis = game.Workspace:WaitForChild("invispartelevator")
local door1 = game.Workspace:WaitForChild("door1")
local door2 = game.Workspace:WaitForChild("door2")
local tppart = game.Workspace:WaitForChild("tppartelevator")
local eror = game.Workspace:WaitForChild("erorpart")
local erordi = game.Workspace:WaitForChild("dieror")
local truedi = game.Workspace:WaitForChild("gooddi")


local function activation()
	door1:Destroy()
	task.wait()
	door2:Destroy()
	task.wait()
	invis:Destroy()
	task.wait()
	eror:Destroy()
	tppart.CanTouch = true
	task.wait()
	erordi:Destroy()
	task.wait()
	truedi.Position = Vector3.new(19.371, 13.884, -64.208)
	task.wait(1)
	print("why???")
end

f3part.Touched:Connect(activation)

It could be because you’re chaining task.wait() calls but I’m not sure. :angst:
Is there anything else you can tell us?

What do you mean by chaining task.wait() calls? I’ve done this same thing in many other localscripts and they all worked out fine. What would be a solution to this, replacing the task.waits with regular wait()s, or just removing them altogether?

I’m confused, why would you use task.wait() without any time parameters?

1 Like

Try removing them, I don’t see why you’d want them there anyway.

@ProgrammerNovice task.wait() waits like 1 / 60 of a second if you don’t give it a wait time.

It may be due to using LocalScript to change the workspace. Try placing a normal script inside ServerScriptService with your code instead.

Help with my flower: the sequel

No but really, if it’s a localscript inside a part in workspace, you need to make it a normal script instead. Local scripts can only be ran on, well, obviously things only the client can be in and access. The workspace is not one of those. Usually, you can only put local scripts in StarterPack, StarterPlayerScripts, StarterCharacterScripts, StarterGui, ReplicatedFirst, and ReplicatedStorage. All of these services are also things it can access, so for example I put a value in replicatedstorage, well I’m able to access it on the client. Ok, hear me out, the client can access EVERYTHING BUT ServerStorage and ServerScriptService. Those go to the server in all its glory. Client scripts just can’t be in certain areas but can access them.

2 Likes

Try this on real quick. Replace your current script with this one and paste the output. If you already have other items outputting try to isolate your script in a different project or turn off the rest.

local f3part = game.Workspace:WaitForChild("F3Part")
local invis = game.Workspace:WaitForChild("invispartelevator")
local door1 = game.Workspace:WaitForChild("door1")
local door2 = game.Workspace:WaitForChild("door2")
local tppart = game.Workspace:WaitForChild("tppartelevator")
local eror = game.Workspace:WaitForChild("erorpart")
local erordi = game.Workspace:WaitForChild("dieror")
local truedi = game.Workspace:WaitForChild("gooddi")

print("F3Part Starting Check" .. f3part)
print("invis Starting Check" .. invis)
print("door2 Starting Check" .. door2)
print("tppart Starting Check" .. tppart)
print("eror Starting Check" .. eror)
print("erordi Starting Check" .. erordi)
print("truedi Starting Check" .. truedi)

local function activation()
    print("F3Part Ending Check" .. f3part)
    print("invis Ending Check" .. invis)
    print("door2 Ending Check" .. door2)
    print("tppart Ending Check" .. tppart)
    print("eror Ending Check" .. eror)
    print("erordi Ending Check" .. erordi)
    print("truedi Ending Check" .. truedi)

	door1:Destroy()
	task.wait()
	door2:Destroy()
	task.wait()
	invis:Destroy()
	task.wait()
	eror:Destroy()
	tppart.CanTouch = true
	task.wait()
	erordi:Destroy()
	task.wait()
	truedi.Position = Vector3.new(19.371, 13.884, -64.208)
	task.wait(1)
	print("why???")
end

f3part.Touched:Connect(activation)

If I messed up some of the variables please just replace them with the correct ones!

So, a few things: I don’t understand why the previous commenters are crying about task.wait() not having parameters; I suggest they open up the Roblox Studio resources. Besides this, those task.wait() are indeed useless but you can keep them if you really want.
Now, why can’t your local script modify .CanTouch? I believe it’s beacause .CanTouch is a property of an object in the workspace that’s not owned by the player at the moment this script runs. If the physics node ownership was up to the player it’d probably have different results, but since it’s the server having the ownership of the part, so of its properties, you can’t really do anything. What’s more intriguing is that it doesn’t work even locally. I would’ve expected a different result ngl. But I think this is it.

P.S.: those :WaitForChild() are also unnecessary. Local scripts will load after the server is already loaded, so objects will exists. Just remove them.

i am a beginner scripter, but can it be because the touched event is being fired multiple times, try using touched once. but the reply above me is probably correct, client vs server authority

Not at all. If it fired multiple times it should still be running the code, although multiple times, lol. The problem is to be found somewhere else.

i gonna be wrong lol, but if for example, u touch it it runs the code and destroys the door and then touching it again, it tries to destroy smth that doesnt exist. uh

Oh you mean that. But his problem is not the door not being destroyed, but the following parts that don’t happen, i.e. the .CanTouch property changing. That’s should happen already on the first interaction, so there is another issue somewhere else.

I removed the task.wait()'s but the same issue is still occuring.

I’m a little confused on what you mean here, but the LocalScript is inside of StarterPlayerScripts if that helps.

Also I get it’s bad but I wouldn’t call it ‘help with my flower the sequel’ haha

The output is saying the following things:

“Script ‘Players.ProVrsNoob311.PlayerScripts.FlrActivateScript’, Line 10 - Studio - FlrActivateScript:10”
“Players.ProVrsNoob311.PlayerScripts.FlrActivateScript:10: attempt to concatenate string with Instance - Client - FlrActivateScript:10”

I probably should have further elaborated on this in the original post, but the things that happen are just random for some reason. Sometimes the door will be destroyed but the .Touched will not activate, or the .Touched will activate and the door doesn’t get destroyed, etc. etc.

Also I saw your previous post explaining how the possible problem could be that it’s the server ownership of the part. I’m somewhat new to scripting, but does that mean that there’s basically nothing I can do?

If you have tppart 's CanTouch setted to false by default and tppart.Touched in server script it won’t work because your assigning tppart.CanTouch in local script to true.

Hey guys, so I found the solution.

The answer? Nothing. I decided that I should test out this in a testing place rather than inside roblox studio, and it works just fine after testing it many times. So apparently the issue was just studio itself. Thank you guys for replying and stuff, I appreciate it.

If something goes wrong and stops working I’ll reopen this thread I guess, but I don’t think that’ll happen.

1 Like

It’s a little stupid but basically what I’m saying is that you can change stuff ON THE CLIENT SIDE but not stuff in ServerStorage or ServerScriptService. Those are services meant for the, well, server