I won't claim to be an experienced coder, but as long as I'm working with basic stuff or with systems that flow with what Roblox does normally I'm fine and for the most part, the game I'm working on has made great progress, but, I am still inexperienced and after browsing every tutorial I can find and help page covering the question I have. I still cannot get what I want to work.
What I want: I'm working on a round-based game with horror elements that I won't go into details on. The issue I faced was not being able to interact with clickDetectors while holding a tool, which is a problem when your game is dark and you need to unequip your light source to fumble around in the dark while trying to open doors and pick things up.
My solution? Bind the two main light sources, a lighter and a flashlight with a battery limit to two keys that toggled them with a simple animation in the lefthand/offhand. R for flashlight, F for lighter.
My Problem: I started with the lighter, and I got about as far as the toggle for the animation of holding out your hand before I hit a hard wall for myself and my coding ability. I cannot for the life of me, get it to weld the handle of the lighter to the left hand. I'm constantly thrown errors, or it just doesn't work. The lighter is already scripted out as a tool, I just need to convert the lighting effects and such to the custom offhand code, but I can't do that if I can't even get it to attach the lighter to the hand. I don't even want to imagine what the flashlight is going to be like, as it's much more complex in its scripting and functionality with its battery system.
As it is now, I have a localscript that does the animations, then fires a remoteEvent to trigger the server script to weld the parts to the hand. I'll show what I have.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local debounce = false
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.F then
if not debounce then
debounce = true
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://6030046535"
Animation.Parent = player.Character
Animate = Humanoid:LoadAnimation(Animation)
Animate.Priority = Enum.AnimationPriority.Action
Animate:Play()
wait(0.5)
Animate:AdjustSpeed(0)
script.RemoteEvent:FireServer()
else
Animate:Stop()
debounce = false
end
end
end)
This is my current welding script. I'm calling on myself directly in the script simply because it doesn't want to detect the lefthand unless I do it this way
local hand = workspace.whiisperer.LeftHand
local Tool = script.Parent.Handle
script.Parent.RemoteEvent.OnServerEvent:Connect(function()
local Weld = Instance.new('Weld',hand)
Weld.C0 = hand.CFrame:inverse() * Tool.CFrame
Weld.Part0 = hand
Weld.Part1 = Tool
end)
Here is an image of the script layouts and the lighter being targeted for weldings (The Handle brick) And a gif of the animation as it is right now, without anything being welded to the hand if that's useful.
tl:dr I can't find a working example that allows me to weld a scripted/complex model to my left hand. I want to equip and light a lighter in my left hand when F is pressed, then put it away when pressed again.
