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

Why is my InvokeServer() not working? Error "attempt to call method 'InvokeServer' (a nil value)",

Asked by 6 years ago
Edited 6 years ago

Here's the code. It doesn't work in studio. In the Local Script:

script.Parent.MouseButton1Click:Connect(function()
    local function serverusernamekill()
        local usernamekill = script.Parent.Text
        return usernamekill
    end
    serverusernamekilltoserver = serverusernamekill()
    serverusernamekilltoserver:InvokeServer()
end)

In the Normal Script:

function serverusernamekilltoserver:OnServerInvoke()
    print("cake")
end

Here's the thing. The "script.Parent.Text" part in the first part is grabbing the text from a button, for context. It then puts it in a variable and returns it in a function so I can pass it to the normal script. I put the function in a variable so I can use "InvokeServer()" with it. I add it to InvokeServer(), but then I get the error "attempt to call method 'InvokeServer' (a nil value)". Can anyone help? :D

Solved. Also, if a local script from ReplicatedStorage is firing to a global script in ServerStorage, move that global script to ServerScriptService if it's not responding. I didn't accept this answer cause I made that mistake and thought it was somehow a problem with this script. Thanks for the reply!

1 answer

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago

InvokeServer is meant to be called on RemoteFunctions, but instead, you have called it on a string. (text).

Make a RemoteFunction in ReplicatedStorage called SendUsername

local SendUsername = game:GetService("ReplicatedStorage"):WaitForChild("SendUsername")

script.Parent.MouseButton1Click:Connect(function()
    SendUsername:InvokeServer(script.Parent.Text)
end)
local SendUsername = game:GetService("ReplicatedStorage"):WaitForChild("SendUsername")

function SendUsername.OnServerInvoke(player,text) -- Use a dot, not a colon.
    print("cake")
end

For more about this, go to the wiki

0
Solved. Also, if a local script from ReplicatedStorage is firing to a global script in ServerStorage, move that global script to ServerScriptService if it's not responding. I didn't accept this answer cause I made that mistake and thought it was somehow a problem with this script. Thanks for the reply! canudoitformeornot 7 — 6y
Ad

Answer this question