The door is open but im want do close with tweenin im create local script
https://gyazo.com/a4dc78462932f4d10b1364f432cb644b
And im create remotefunction in ReplicatedStorage
And im create script in ServeScriptService
https://gyazo.com/707466efa5c0a46267f9c6a12d5f0235
Im want close but write this is erros
https://gyazo.com/c1f126532d59d0c5f5df92a871367395
Either the character doesn’t exist yet or there is a child in the workspace named the player’s name.
Another way you should get the character (instead of going the find player name in workspace method) is by using player.Character
.
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait() --characteradded is used incase the character doesn't load when this is called
You should also use WaitForChild often.
local RootPart = Character:WaitForChild("HumanoidRootPart") --this way you have the root part without error
Still doesnt working now its write this is error
https://gyazo.com/18c6bf932fd1693beab93835cb28dd75
But door is in the model
Like I told you, use WaitForChild
. If you don’t use WaitForChild, you will get errors like that since the model Door is not in the workspace yet.
Still it doesnt working here script and is localscript https://gyazo.com/63752130e49b3e28508544abadbd7c45
You should use WaitForChild
on the first reference to the instance. I recommend you read the documentation for it on the developer hub so you can better understand what it is and what it does.
In simple terms, it will yield your code until said child is found within an instance, this is important as not all objects may be replicated to the client at the time of running the code.
Like I said, use WaitForChild. I don’t see any use of WaitForChild, therefore your scripts could be erroring due to that. It could also be due to the fact the child Door
does not exist in your model. Check your model names.
You should apply WaitForChild
on all the instances, like this:
workspace:WaitForChild("safe"):WaitForChild("Sliding"):WaitForChild("Door")
A more simple way would be to create a variable rather than referencing the directory every time. Here is an example:
local door = workspace:WaitForChild("safe"):WaitForChild("Sliding"):WaitForChild("Door")
TweenService:Create(door, TweenInfo, Goal):Play()
door.CanCollide = true
door.Anchored = true
Getting better. You should also use workspace
instead of game.Workspace
, as it is easier to type and you don’t have to call game.
I would say it would be better to give each parent a variable instead of just doing simultaneous WaitForChilds
.
You have probably forgotten to change the first parameter of TweenService:Create()
as this was not using WaitForChild
.
Oh sorrry thank im try again wait a minute
Door:WaitForChild(“Door”)? That doesn’t make sense.
Here is an example of what the code should look like.
local door = workspace:WaitForChild("safe"):WaitForChild("Sliding"):WaitForChild("Door"):WaitForChild("Door")
UserInputService.InputBegan:Connect(function(inputObject, gameProcessed)
if gameProcessed then return end
if inputObject.KeyCode == Enum.KeyCode.E and (character.HumanoidRootPart.Position - door.Position).Magnitude <= 5 then
TweenService:Create(door, TweenInfo.new(3, Enum.EasingStyle.Bounce, Enum.EasingDirection.In), {Position = Vector3.new(99.754, 6.295, -152.18)}):Play()
door.CanCollide = true
door.Anchored = false
end
end)
You should use the gameProcessed
parameter to detect if the user pressed “E” to do something such as chat. I added a door
variable at the top of your script so you only need to reference its directory once.
The error you received is due to WaitForChild
taking longer than 5 seconds to return the instance. This is usually because the instance does not exist in the given directory, so you should double check if everything is in the right place and that you are in fact referencing the correct directory.
Okey now its write anything but the door is do not move https://gyazo.com/1c293086d9357b764c763107dc4c6db8
Make sure you’re playing your tweening animation, and make sure you do the math correctly.