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!
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?