Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would you convert something like this over when using the new client filtering?

For example, say I had something like this:

mouse=Game.Players.LocalPlayer:GetMouse();
mouse.KeyDown:connect(function(key)
if key:lower()=='e' then
Instance.new("Explosion",mouse.Target)
end
end)
--Please note that I'm not actually using the above code for anything, it's just an example.

The new filtering doesn't allow of using Instance.new() in a LocalScript from what I know about it, so how would I go about doing something like this?

2 answers

✓ Accepted answer

You need to use RemoteFunctions - these ARE allowed to be used with FilteringEnabled.

This goes on the server script:

local RemoteFunction = Instance.new("RemoteFunction")
RemoteFunction.Name = "CreateExplosion"
RemoteFunction.Parent = game.ReplicatedStorage
function RemoteFunction.OnServerInvoke(Position)
local new = Instance.new("Explosion", game.Workspace)
new.Position = Position -- note: explosions have a position property, putting them in a random part just creates an explosion on (0,0,0)
end

This in the client:

function CreateExplosion(pos)
game.ReplicatedStorage.CreateExplosion:InvokeServer(pos or Vector3.new(0,0,0)) 
end

mouse=Game.Players.LocalPlayer:GetMouse();
mouse.KeyDown:connect(function(key)
if key:lower()=='e' then
CreateExplosion(mouse.hit.p)
end
end)

01 function CreateExplosion(pos) 02 game.ReplicatedStorage.CreateExplosion:InvokeServer(pos or Vector3.new(0,0,0)) 03 end 04

05 mouse=Game.Players.LocalPlayer:GetMouse(); 06 mouse.KeyDown:connect(function(key) 07 if key:lower()=='e' then 08 CreateExplosion(mouse.hit.p) 09 end 10 end)

This discussion is preserved as it was. New answers, comments, and votes are closed.