Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why isn't this detecting the RemoteEvent?

Asked by
stupru 11
3 years ago
Edited 3 years ago

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)
0
Is semiEvent in ReplicatedStorage or is it a folder or replicated storage? Master_Aaron 59 — 3y
0
its inside replicatedstorage stupru 11 — 3y
0
Maybe try going in game, and switch to the server and see if the event is in replicated storage Phase_Venom 55 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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.

Ad

Answer this question