local Players = game:GetService("Players")
script.Parent.Touched:Connect(function(hit)
local plr = Players:GetPlayerFromCharacter(hit.Parent)
local char = plr.Character
local anim = script.Animation
local animtrack = plr.Character.Humanoid:LoadAnimation(anim)
animtrack:Play()
if script.Parent.Parent.door.CFrame == script.Parent.Parent.door.open.CFrame then
char.HideWithDoor.Value = 1
end
if script.Parent.Parent.door.CFrame == script.Parent.Parent.door.close.CFrame then
char.HideWithDoor.Value = 2
end
end)
script.Parent.TouchEnded:Connect(function(hit)
local plr = Players:GetPlayerFromCharacter(hit.Parent)
local char = plr.Character
local anim = script.Animation
local animtrack = plr.Character.Humanoid:LoadAnimation(anim)
animtrack:Stop()
char.HideWithDoor.Value = 0
end)
basically its supposed to play the animation while the player is touching the part and increase the value to 1 if the door is opened and to 2 if its closed and when the player isnt touching the part to stop the animation and make the value 0
but the script cant stop the animation and is unable to get the values
Can you provide a screenshot of the explorer in game? or where HideWithDoor is located. There doesn’t look to be enough information to solve your problem. Also I believe the script can’t stop the animation because you’re trying to use LoadAnimation in a separate location where it isn’t already playing. You should use a variable outside of both Touch connections so you can use Stop in your TouchEnded Connection.
-- Assuming this is a ServerScript --
local Players = game:GetService("Players")
local AnimationTrack = nil
script.Parent.Touched:Connect(function(hit)
local plr = Players:GetPlayerFromCharacter(hit.Parent)
local char = plr.Character
local anim = script.Animation
AnimationTrack = plr.Character.Humanoid:LoadAnimation(anim)
...
script.Parent.TouchEnded:Connect(function(hit)
AnimationTrack:Stop()
char.HideWithDoor.Value = 0
end)
I mean you don’t have to you can just leave it blank and not give it a value, but that’s just the way i’m used to doing it. Now for my question, is HideWithDoor there on both the Client and Server?
You can’t access the character when the player joins through just PlayerAdded by itself
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local value = Instance.new("NumberValue")
value.Parent = Character
value.Name = "HideWithDoor"
end)
end)
local Players = game:GetService("Players")
local animtrack = nil
script.Parent.Touched:Connect(function(hit)
local plr = Players:GetPlayerFromCharacter(hit.Parent)
local char = plr.Character
local anim = script.Animation
animtrack = char.Humanoid:LoadAnimation(anim)
animtrack:Play()
if script.Parent.Parent.door.CFrame == script.Parent.Parent.door.open.CFrame then
char.HideWithDoor.Value = 1
end
if script.Parent.Parent.door.CFrame == script.Parent.Parent.door.close.CFrame then
char.HideWithDoor.Value = 2
end
end)
script.Parent.TouchEnded:Connect(function(hit)
local plr = Players:GetPlayerFromCharacter(hit.Parent)
local char = plr.Character
local anim = script.Animation
local animtrack = nil
animtrack = char.Humanoid:LoadAnimation(anim)
animtrack:Stop()
char.HideWithDoor.Value = 0
end)
tried to fix the stop thing with the nil solution but it didnt help in anything (no output error)
Okay, i don’t think you understood what i put for you. The code that I wrote is basically what you should have, you only need those two lines in your TouchEnded code. Also sorry for the late reply