Forcefield issues

I am making a dodge roll system, and I am trying to make an invisible forcefield pop up while the player is rolling, but It isn’t working

Local script in starterplayerscripts

local char = game.Players.LocalPlayer.Character
local uis = game:GetService("UserInputService")
local cooldown = false
uis.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.LeftShift then
	if cooldown == true then
	end
	if cooldown == false then
		cooldown = true
		local anim = script.Roll
		local hum = game.Players.LocalPlayer.Character.Humanoid
		local track = hum:LoadAnimation(anim)
		track:Play()
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 32
			game.ReplicatedStorage.DodgeEvent:FireServer(char)
			wait(.8)
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
			wait(2)
			cooldown = false
			end
		end
	end
end)

Serverscript in ServerScriptService

game.ReplicatedStorage.DodgeEvent.OnServerEvent:Connect(function(char)
	local ff = Instance.new("ForceField")
	ff.Visible = false
	ff.Parent = char
	wait(0.8)
	ff:Destroy()
end)
2 Likes

When using OnServerEvent, the connected function will have one additional param (the player who fired the event)

game.ReplicatedStorage.DodgeEvent:FireServer(char)

should be met with

game.ReplicatedStorage.DodgeEvent.OnServerEvent:Connect(function(player, char)
2 Likes

this has already been solved by @tyzone (i think)

but some things i wanna point out:

you do not need that if cooldown == false statement, since the code will already cancel out if the cooldown is active


just use the char variable to find the humanoid :grimacing:

2 Likes

I made the char variable after writing those so it would just be a waste of time to rewrite it

game.ReplicatedStorage.DodgeEvent.OnServerEvent:Connect(function(player, char)
	local ff = Instance.new("ForceField")
	ff.Visible = false
	ff.Parent = char
	wait(0.8)
	ff:Destroy()
end)

Still doesnt work

Any errors in console? Try adding a bunch of prints here and there to see which parts of the code are being run and which aren’t?

i introduced this variable to make my life easier but i will not use it :broken_heart:

game.ReplicatedStorage.DodgeEvent.OnServerEvent:Connect(function(player, char)
	print("Event recieved")
	local ff = Instance.new("ForceField")
	print("FF created")
	ff.Visible = false
	ff.Parent = char
	wait(0.8)
	print("FF destroyed")
	ff:Destroy()
end)

All of these print statements worked

well i mean, the forcefield IS invisible, maybe that’s why you can’t see it :face_with_hand_over_mouth:

temporarily remove the :Destroy(), and upon firing the remote event, check the character in the explorer

I have checked with making the forcefield visible too, and I also have a damage brick to test

but does the forcefield Actually exist inside of the character?
that’s what i’m asking

Just tested that, and there is no forcefield, idk why

hmmm,

can you print char on the server script and see what it gives out?

it outputted nil, ima try to fix that

ah, i see the issue

in your local script, the character variable should probably be set to this:

local char = plr.Character or plr.CharacterAdded:Wait()