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!
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