Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

With FilteringEnabled, how do you make a forcefield?

Asked by 9 years ago

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.

1 answer

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

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)
0
After fixing some careless mistakes, it works! Thanks! omgiforgot123 5 — 9y
0
You're welcome. Redbullusa 1580 — 9y
Ad

Answer this question