- What do you want to achieve? I’m trying to find a way to pass my “hit” parameter for my carry script. Here’s how my carry script will work:
- When you hold R, you’re able to physically touch someone with the touched event, and grab and carry them. Then when they’re welded to you, you have to keep holding R to carry them.
- When you let go of R, you stop carrying them by breaking the weld.
-
What is the issue? I can’t find any way for my Input events to access the same hit parameter. The carrying part is easy, but the un-carrying part is harder.
-
What solutions have you tried so far? I tried putting my InputEnded in the scope of the touched event, which is in a for i,v loop looping through the children of the player’s character, which is inside the InputBegan. So basically what I tried:
Summary
UIS.InputBegan:connect(function(key,blah)
if blah then return end
if key.KeyCode = Enum.KeyCode.R then
for i,v in pairs(char:GetChildren())do
if v:IsA('BasePart) or v:IsA('MeshPart) then
v.Touched:connect(function(hit)
--send remote event to server to create the weld and send hit parameter
InputEnded:connect(function(key,blah)
if blah blah blah then
--send remote event to server to destroy weld and send hit parameter
end
end
end)
end
end
end
end)
I also tried handling the touch event on the server, which is where I am at now. But I have the same issue. :[ Here is what I have so far:
Local script
--[Local script]--
local player = game:GetService('Players').LocalPlayer
local UIS = game:GetService('UserInputService')
local Players = game:GetService('Players'):GetChildren()
local RS = game:GetService('ReplicatedStorage')
local char = player.Character or player.CharacterAdded:wait()
local HRP = char:FindFirstChild('HumanoidRootPart')
local isCarrying = false
local rPressed = false
UIS.InputBegan:connect(function(key,blah)
if blah then return end
if key.KeyCode == Enum.KeyCode.R then
rPressed = true
isCarrying = true
if rPressed and isCarrying then
RS:WaitForChild('RemoteEvents').Flying.Carrying:FireServer(isCarrying)
end
end
end)
UIS.InputEnded:connect(function(key,blah)
if blah then return end
if key.KeyCode == Enum.KeyCode.R then
rPressed = false
isCarrying = false
if not rPressed and not isCarrying then
RS:WaitForChild('RemoteEvents').Flying.Carrying:FireServer(isCarrying)
end
end
end)
Server script
local RS = game:GetService('ReplicatedStorage')
local DB = false
RS.RemoteEvents.Flying.Carrying.OnServerEvent:connect(function(player,isCarrying) --[when inputBegan key = r, then isCarrying = true; when inputEneded key = r, then isCarrying = false]
local char = player.Character
if isCarrying then
for i,v in pairs(char:GetChildren()) do
if v:IsA('BasePart') or v:IsA('MeshPart') then
v.Touched:connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') and not DB then
local targetChar = hit.Parent
DB = true
print('true')
end
end)
end
end
else
DB = false
print('false')
end
end)
Nothing really changed lmao…how do I achieve my goal?