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

My script wont run correctly. What is the incorrect Lua speak I am using and how do I fix it?

I am EXTREMELY new to scripting. Like I started this morning. I have two parts that make up a door in different positions, open and closed (They are named as such) and when a player presses e, I want one to turn invisible and be able to walk through with the other appears and turns unable to walk through. Does that make sense?

The script is as follows:

Close = script.Parent.Close
Open = script.Parent.Open

game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(k)
if k == "e" then
	game.Workspace.Close.Transparency = 1
	game.Workspace.Close.CanCollide = false
	
	game.Workspace.Open.Transparency = 0
	game.Wrokspace.Open.CanCollide = true 
		if game.Workspace.Close.Transparency = 1 then
			game.Workspace.Close.Transparency = 0
			game.Workspace.Close.CanCollide = true
			
			game.Workspace.Open.Transparency = 1
			game.Workspace.Open.CanCollide = false
		end
		end
	end
	
end

Like I said, I am not even sure any of this is for the right function. I am fairly certain the issue lies the in the game.Workspace.Open. I don't think those are the right terms for my desired object.

3 comments

0

ruben wth are you doing

0

Ruben what do you mean? Or are u just being an idiot?

0

You spelled 'workspace' incorrectly on line 2

1 answer

Okay, I didn't really understand your goal, but I think you have a model(the door?) which has 2 parts in it('Close' and 'Open'), and you have this script in the model.

So, first: You're assigning "Close" as the part called "Close" in the model, same with "Open". That's right, but I didn't understand why did you use game.Workspace.Close and game.Workspace.Open as you don't really need them. You've already assigned the parts 'Close' and 'Open' as "Close" and "Open" in the script, so when calling them you should use Open.whateverproperty and Close.whateverproperty instead.

Second, you used LocalPlayer which requires a local script if you don't know. I suggest using UserInputService instead - which doesn't require a local script.

So, the beginning of your script would be like:

Open = script.Parent.Open
Close = script.Parent.Close

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)

Then, you need to check what key was pressed, so you write an if conditional statement to check if the KeyCode pressed of the inputObject is 'e'. Your script would be like this:

Open = script.Parent.Open
Close = script.Parent.Close

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.E then
 -- here: write the code that you want
    end 
end
end)

Finally, you can write your code, and remember to use 'Open' and 'Close' instead of 'game.Workspace.Open' etc.

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