This is what I've gotten to so far.
-- in local script local ReplicatedStorage = game:service('ReplicatedStorage') local Event = ReplicatedStorage:FindFirstChild('RemoteEvent') local Mouse = Player:GetMouse() Mouse.KeyDown:connect(function(Key) if Key() == 'f' then print('pressed f!') Event:FireServer('message') wait(8) end end)
-- in server script local Player = game:GetService('Players') local ReplicatedStorage = game:GetService('ReplicatedStorage') local Event = ReplicatedStorage:FindFirstChild('RemoteEvent') local shield = true Event.OnServerEvent:connect(function(player, msg) if msg == 'message' then print('recieved message') shield = false local ff = Instance.new('ForceField') ff.Parent = Player.Character --problem wait(5) ff:Destroy() shield = true end end)
The problem about this code is that I do not know how to get the player's character so I can insert a forcefield into it.
For the second script, you already have the player
argument set up already. Just lowercase Player
, or else you're going to try to get the character object of game.Players
(line 1).
Event.OnServerEvent:connect(function(player, msg) if msg == 'message' then -- ... ff.Parent = player.Character -- ... end end)
There's a second argument for the Instance.new() function that serves the purpose of parenting the new instance.
local ff = Instance.new("ForceField", player.Character)