Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't this detecting the RemoteEvent?

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)

3 comments

0

Is semiEvent in ReplicatedStorage or is it a folder or replicated storage?

0

its inside replicatedstorage

0

Maybe try going in game, and switch to the server and see if the event is in replicated storage

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.