This is the code which is inside a Localscript, the event doesn’t seem to be firing correctly/properly, on range, which is a sphere part and when the humanoid goes in and out it doesn’t seem to fire.
local broom = script.Parent
local range = broom:WaitForChild('Range')
local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild('Humanoid')
local userInputService = game:GetService('UserInputService')
local replicatedStorage = game:GetService('ReplicatedStorage')
local unequipBroom = replicatedStorage.Broom.UnequipBroom
local rideBroom = replicatedStorage.Broom.RideBroom
local leaveBroom = replicatedStorage.Broom.LeaveBroom
local equipBroom = replicatedStorage.Broom.EquipBroom
local remoteFunction = replicatedStorage.Broom.RemoteFunction
local broomEquipped = true
local connection
local connection2
broom.Equipped:Connect(function()
connection = userInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.E then
broomEquipped = false
unequipBroom:InvokeServer(broom)
elseif input.KeyCode == Enum.KeyCode.F then
broomEquipped = false
unequipBroom:InvokeServer(broom)
rideBroom:FireServer(broom)
end
end)
end)
broom.Unequipped:Connect(function()
if connection then
connection:Disconnect()
end
end)
range.Touched:Connect(function(hit)
print(hit, hit.Parent)
if not hit.Parent:FindFirstChild('Humanoid') then return end
print(hit.Parent)
--if broomEquipped then return end
connection2 = userInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
print(input.KeyCode)
if input.KeyCode == Enum.KeyCode.E then
equipBroom:InvokeServer(range.Parent)
elseif input.KeyCode == Enum.KeyCode.F then
leaveBroom:InvokeServer(range.Parent)
equipBroom:InvokeServer(range.Parent)
end
end)
end)
range.TouchEnded:Connect(function(hit)
if not hit.Parent:FindFirstChild('Humanoid') then return end
--if player.Character ~= hit.Parent then return end
--if hit == '' then return end
if connection2 then
connection2:Disconnect()
end
end)```
Just noted couple of problems here but with your range.Touched connection, every time anyone touches it, it will create that new connection because you don’t actually check which player touches it. Also, you don’t need this many inputbegan connections. You can create a variable that shows if the tool is equipped and you can also use :GetTouchingParts() instead of a touch event and put everything within a InputBegan connection. I hope this wasn’t too confusing ik this is like the most confusing thing you’ve ever read but if you have any questions just reply I guess.
local broom = script.Parent
local range = broom:WaitForChild('Range')
local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild('Humanoid')
local replicatedStorage = game:GetService('ReplicatedStorage')
local remoteFunction = replicatedStorage.Broom.RemoteFunction
local broomEquipped = true
local unequipPrompt = broom.Head.UnequipPrompt
local equipPrompt = broom.Shaft.EquipPrompt
local ridePrompt = broom.Shaft.RidePrompt
local leavePrompt = broom.Shaft.LeavePrompt
local unequipBroom = replicatedStorage.Broom.UnequipBroom
local rideBroom = replicatedStorage.Broom.RideBroom
local leaveBroom = replicatedStorage.Broom.LeaveBroom
local equipBroom = replicatedStorage.Broom.EquipBroom
unequipPrompt.Triggered:Connect(function(player)
print('hi', player)
unequipPrompt.Enabled = false
unequipBroom:InvokeServer(broom)
end)
equipPrompt.Triggered:Connect(function(player)
equipPrompt.Enabled = false
unequipPrompt.Enabled = true
equipBroom:InvokeServer(range.Parent)
end)
ridePrompt.Triggered:Connect(function(player)
rideBroom:FireServer(broom)
end)
leaveBroom.Triggered:Connect(function(player)
leaveBroom:FireServer(broom)
end)
No errors. It shows the ProximityPrompt in game I can press the key E but nothing happens after. I’ll try with :WaitForChild.
Update: Still doesn’t seem to work.