I'm trying to fire to the server to damage the player when they get shot, but it gives me the error "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)
If its a Infinite Yeild error try using FindFirstChild or try and simply your code so when the event is connected whatever you wanted to happen, happens.