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

Firing Instance.new RemoteEvent from LocalScript not working?

Asked by 3 years ago

Hello so i'm trying to Instance serversided parts from a localscript using a remoteevent and i keep getting this error.

local function instance(a,b)
    if b then
        return game:GetService("ReplicatedStorage").Instance:FireServer(a,b)
    elseif not b then
        return game:GetService("ReplicatedStorage").Instance:FireServer(a)
    end
end

local cool = instance("Part", workspace)

print(cool) -- Supposed to print part name but prints nil instead

Anyway to fix this?

0
I feel like this can be exploited MarkedTomato 810 — 3y
0
tbh, same. NGC4637 602 — 3y
0
Yeah but its a private project for me and some friends. RemsFriend -24 — 3y

1 answer

Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago
Edited 3 years ago

theres a few problems.

  1. don't use the parent parameter for instance.new, its slow. (only set the parent param if you aren't gonna change any other properties. Otherwise, set the parent property last)

  2. (main problem). you aren't returning the part you instance.new()ed in the server, therefore its not working.

  3. to fix 2, you need to use a remotefunction instead of a remoteevent.

here is the fixed script:

local script

-- local script
function instance(a,b)
    if b then
        return game:GetService("ReplicatedStorage"):WaitForChild("Instance"):InvokeServer(a,b)
    elseif not b then
        return game:GetService("ReplicatedStorage").WaitForChild("Instance"):InvokeServer(a)
    end
end

local cool = instance("Part") -- don't use the parent parameter, its bad. check dev forum to know why
cool.Name = "lol"

print(cool.Name) -- Instances are not strings bruv, should print lol because I set the name to "lol"

server script

-- server script
local RF = game:GetService("ReplicatedStorage"):WaitForChild("Instance")

RF.OnServerInvoke = function(class:string, parent) -- yes you can do this now
    local newPart = Instance.new(class)
    if parent and parent:IsA("Instance") then
        newPart.Parent = parent
    end
    return newPart -- this part you are missing
end
0
Thank you so much, u saved me so much time RemsFriend -24 — 3y
Ad

Answer this question