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
tyzone
(tyzone)
November 13, 2024, 9:21am
2
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
notsad2
(nots7d)
November 13, 2024, 9:24am
3
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
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
tyzone
(tyzone)
November 13, 2024, 9:34am
6
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?
notsad2
(nots7d)
November 13, 2024, 9:37am
7
i introduced this variable to make my life easier but i will not use it
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
notsad2
(nots7d)
November 13, 2024, 9:57am
9
well i mean, the forcefield IS invisible, maybe that’s why you can’t see it
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
notsad2
(nots7d)
November 13, 2024, 10:04am
11
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
notsad2
(nots7d)
November 13, 2024, 10:05am
13
hmmm,
can you print char on the server script and see what it gives out?
it outputted nil, ima try to fix that
notsad2
(nots7d)
November 13, 2024, 10:07am
15
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()
system
(system)
Closed
November 27, 2024, 10:07am
16
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.