Help with tweening touching parts

Im trying to make the tween/camera in this script touch a Part so that an event will trigger, making 2 textbuttons visible.

local Camera = workspace.CurrentCamera
local Views = workspace:WaitForChild("Views2")
local tweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local Right = game.StarterGui.View.ViewRight
local Main = game.StarterGui.View.MainView
local Part = game.Workspace.Hit

function tweenCamera(pos,tweenTime)
	local result = tweenService:Create(Camera,TweenInfo.new(tweenTime,Enum.EasingStyle.Linear), {CFrame = pos.CFrame})
	return result
end

local result =  tweenCamera(Views.ViewRight, 9)
UIS.InputBegan:Connect(function(input)
	if input.KeyCode==Enum.KeyCode.W then
		result:Play()	
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.KeyCode==Enum.KeyCode.W then
		result:Pause()
	end
end)

Part.GetTouchingParts:Connect(function()
	if Part.Touched then
		Right.Visible = true
		Main.Visible = true
	end
end)




I tried to use GetTouchingParts:() to detect the part inorder to trigger the event, but it doesn’t seem to work.

Can someone explain to me if there are any errors in the script, and how I would be able to fix it? Thanks.

2 Likes

If you are waiting until the tween makes the parts touch, then you could just wait until the tween ends like this:

Tween.Completed:Wait()
1 Like

I tried that before, it doesn’t seem to work for some reason.

Can you show me where you are putting it in your script?

Tween.Completed:Wait()
	if Part.Touched then
		Right.Visible = true
		Main.Visible = true
	end
end)

I tried to place it here basically.

Try this:

Tween.Completed:Wait()
	Right.Visible = true
	Main.Visible = true
end)

Touched is “an event only fires as a result of physics movement, so it will not fire if the CFrame property was changed such that the part overlaps another part. This also means that at least one of the parts involved must not be BasePart.Anchored at the time of the collision.”

You can’t do .Completed like that.
https://developer.roblox.com/en-us/api-reference/event/TweenBase/Completed

I tried unanchoring the part and adding this to the script. It still dosen’t work.

Ah yes that is correct. 30char

Tween.Completed:Connect(function(playbackState)
	if playbackState == Enum.PlaybackState.Completed then
		Right.Visible = true
		Main.Visible = true
	end
end)
1 Like

I added it, it still doesn’t seem to work. Do you think the problem is where I placed the script?

Part.Workspace:GetPartsInPart(function()
		Right.Visible = true
		Main.Visible = true
	end)

I added it, but it still doesn’t work.

That’s not how it’s used.

local Parts = workspace:GetPartsInPart(Part)

https://developer.roblox.com/en-us/api-reference/function/WorldRoot/GetPartsInPart

@Forummer’s reply would work in this way:

local PartsInPart = workspace:GetPartsInPart(Part)
for i, part in pairs(PartsInPart) do		
	if part.Name == "whatever the name is" then
		Right.Visible = true
		Main.Visible = true
    end
end	

I tried it, it still doesn’t work.

Do you think the problem is where I placed the script?

Can you show me where you placed the script?

I ended up placing it in StarterCharacterScripts.

If you put it there then it is parented to the players character and if the player dies then it will be deleted. I would put it in StarterGui.

local Right = game.StarterGui.View.ViewRight
local Main = game.StarterGui.View.MainView

Well this isn’t affecting the player… So put it in StarterGui and do this:

local Right = script.Parent.View.ViewRight
local Main = script.Parent.View.MainView

Alright, I tried it and it still doesn’t work.