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

Event has an infinite yield? But I clearly made it?

I made a script that does damage on hit and I made it two different scripts. One makes an event and all of the hitbox creation, along with animation in the future, and the other does the damage. But when I made the other script, it kept giving me =

21:00:05.939 - Infinite yield possible on 'ReplicatedStorage:WaitForChild("BAttack")'

I know what it means, but i'm not sure why its giving me this. My print BAttack is working, but the damage is not.

Server Script in Starter Pack

-Doesn't work

local event = game.ReplicatedStorage:WaitForChild("BAttack") or game.ReplicatedStorage.BAttack 

event.OnServerEvent:Connect(function(player)	
print("adsljkaa")

		if player then
			local humanoid = player.Parent.FindFirstChild("Humanoid")
			
			humanoid:TakeDamage(6)


		end
end)

Local Script in Starter Pack

-Does work

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
--local r = char.RightShoulder
local mouse = player:GetMouse()
local sword = char:WaitForChild("BSword") or char.BSword
local event = Instance.new("RemoteEvent", game.ReplicatedStorage) or game.ReplicatedStorage.BAttack
event.Name = "BAttack"

mouse.Button1Down:Connect(function()

		--the hitbox
		print("okok")
	local hit = Instance.new("Part", workspace)
	hit.Color = Color3.new(100, 0, 0)
	
	
	hit.CFrame = sword.CFrame:ToWorldSpace(CFrame.new(0,0,3))
	 
	hit.Anchored = true
	hit.CanCollide = false
	hit.Touched:Connect(function(h)
	event:FireServer(h)
	print(event.Name)
		end)
		wait(.5)
		hit:Destroy()
		end)

Thanks for looking!

1 comment

0

I think having a server script in starter pack is not a good idea...

1 answer

✓ Accepted answer

Roblox games are Filtering Enabled. Which means that local scripts are only ran on the client(players computer) and server scripts are ran on the server. This is done to prevent exploiters, lets say an exploiter created a brick on his client, it would not be seen on the server meaning other players would not see it either, only the exploiter would.

Im guessing the problem here is that you are creating the remote event on the client(players computer), so it is not replicated to the server, which is why the server cannot find it.

To fix this I would say just put the remote event in the replicated storage instead of dynamically creating it, unless there is a reason you are?

3 comments

0

I will try this and see if it works. I knew it had something to do with the client/server. Thanks!

0

Yeah no problem, let me know how it goes. If tht doesn’t work we can try to find another solution.

0

Yup, your solution works! I just need to make it find the humanoid somehow. Apperently it doesnt see what player is, and i thought player was passed from the event:FireServer. Anyway thanks.

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