Hey! I’m working on a gun script, and I’m having troubles using the RemoteEvent. When I click, the output says “Infinite yield possible on ‘ReplicatedStorage:WaitForChild(“semiEvent”)’”
LocalScript
-- Variables
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local equipped = false
-- Raycasting Function
local function semiFire()
local camera = workspace.CurrentCamera
local semiParams = RaycastParams.new()
semiParams.FilterDescendantsInstances = {}
semiParams.FilterType = Enum.RaycastFilterType.Blacklist
local function semiResult(x, y)
local unitRay = camera:ScreenPointToRay(mouse.x, mouse.y)
return workspace:Raycast(unitRay.Origin, unitRay.Direction * 500, semiParams)
end
local semiResultV = semiResult()
if semiResultV then
local hitPart = semiResultV.Instance
local humanoid = hitPart.Parent:FindFirstChild("Humanoid")
if not humanoid then
local humanoid = hitPart.Parent.Parent:FindFirstChild("Humanoid")
end
if not humanoid then end
if humanoid then
print("shoot person (blehh)")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local semiEvent = ReplicatedStorage:WaitForChild("semiEvent")
semiEvent:FireServer(humanoid)
end
end
end
-- Equip / Unequip
tool.Equipped:Connect(function(mouse)
equipped = true
end)
tool.Unequipped:Connect(function(mouse)
equipped = false
end)
-- Firing
UserInputService.InputBegan:Connect(function(input)
if equipped == true then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
semiFire()
print("shoot (kaboom)")
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if equipped == true then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
end
end
end)
Script
local semiEvent = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
semiEvent.Name = semiEvent
local function onSemiEventFired(humanoid)
humanoid:TakeDamage(35)
end
semiEvent.OnServerEvent:Connect(onSemiEventFired)
Hierarchy