Recently i’m trying to create an NPC to interact with in a different way than the normal ROBLOX interactive system.
Straight to the issues:
The local player’s camera doesn’t tween as he touches the sensor i’ve created. It works only after a few seconds or after a few touches with the sensor. Is it because of the wrong way i have placed the debounce?
The tween works just as fine but when it reaches the end it comes back at the player in it’s normal mode. I want to keep it there until a player stops talking with the NPC or stops the conversation with it.
This is more of a shortcut question so i won’t create another topic for it. In the script below is it possible to create multiple functions in the fired event? For an example, is it possible for the NPC to start “talking” as the tween ends, giving the player decisions and many other things, while not breaking the function at the same time?
Here is the local script inside the UI part that it will be animated later :
local touchSensor = game.Workspace.TouchSensor
local TweenService = game:GetService("TweenService")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local tween = TweenService:Create(camera,
TweenInfo.new(2,
Enum.EasingStyle.Quart,
Enum.EasingDirection.InOut),
{CFrame = game.Workspace.Camera1.CFrame,Focus = game.Workspace.CameraFocus.CFrame})
game.ReplicatedStorage.OpenGui.OnClientEvent:Connect(function()
tween:Play()
end)
local touchSensor = game.Workspace.TouchSensor
local debounce = false
touchSensor.Touched:Connect(function(hit)
if not debounce then
debounce = true
if game.Players:GetPlayerFromCharacter(hit.Parent)then
game.ReplicatedStorage.OpenGui:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
end
wait(2)
debounce = false
end
end)
Sadly i am still a beginner in scripting so i apologize in advance if i don’t understand something fast.
Thank you all !
Maybe you should check if the thing that touches the sensor is a humanoid so the debounce doesn’t start when anything touches it try this:
local touchSensor = game.Workspace.TouchSensor
local debounce = false
touchSensor.Touched:Connect(function(hit)
if hit.Parent.Humanoid then
if not debounce then
debounce = true
if game.Players:GetPlayerFromCharacter(hit.Parent)then
game.ReplicatedStorage.OpenGui:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
end
wait(2)
debounce = false
end
end)
The code you gave me breaks the script i guess. It doesn’t work at all. Plus there are no other parts touching the sensor since its anchored in the air where only the players can touch it.
Oh sorry my bad for forgetting an end but, not using findfirstchild works fine for me and he got to check if it’s a character after the debounce is played so if it’s touched by an accesory debounce will play without playing the tween. (From what I’ve seen)
There are no errors and indeed i used prints. As @BawTheSeal mentioned, if i touch the sensor with an accessory and then with my body, the tweening wont run (if i go backwards into the sensor while wearing wings for an example)
local touchSensor = game.Workspace.TouchSensor
local debounce = false
touchSensor.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if game.Players:GetPlayerFromCharacter(hit.Parent)then
if not debounce then
debounce = true
game.ReplicatedStorage.OpenGui:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
end
wait(2)
debounce = false
end
end
end)
I used FindFirstChild and didn’t forget the end (heh…).
Maybe you already tried this tho. Tell me if you did!
@BawTheSeal I used FindFirstChildWhichIsA (“Humanoid”) and the script works now no matter with what i touch the sensor.
touchSensor.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
if not debounce then
debounce = true
if game.Players:GetPlayerFromCharacter(hit.Parent)then
game.ReplicatedStorage.OpenGui:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
end
wait(2)
debounce = false
end
end
end)
Thank you both for helping and now, if you two are still here , will the script break if i insert multiple functions inside touchSensor.Touched:Connect(function(hit)) ?