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

Why is my function not running at all?

Asked by 3 years ago

Issue

Simply put; when I try to fire my function through a remote event... it's returns with the error of > attempt to call a string value.

Explanation.

I want to use a system that automatically calls the proper function through a remote event.

Error Script

game.ReplicatedStorage.ControlEvents.ShowEvent.OnServerEvent:Connect(function(plr,Show,Trigger)
    Show(Trigger)
end)

Fire Script

--//Made By MillerrIAm
local Event = game.ReplicatedStorage.ControlEvents.ShowEvent
--//Main Script
script.Parent.MouseButton1Click:Connect(function()
    Event:FireServer(script.Parent.Parent.Label.Text,"Intro")
end)

Thank you for any help you can give me.

2 answers

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
3 years ago
Edited 3 years ago

What you sent across to the server is not a function, the Show parameter is the text value of a label, so you should set label equal to the Trigger:

game.ReplicatedStorage.ControlEvents.ShowEvent.OnServerEvent:Connect(function(plr,Show,Trigger)
    Show = Trigger
end)

You can't change a string value like you did, it's that simple.

Edit: Now looking back on it, it was confusing because you didn't provide us with anything to do with functions, so if you wanted your error script to run a function that is of the name of the label's text, you would need a table of functions (in a module script if you know how to use them):

local tableOfFunctions = {
    ["Show"] = function(thing)
        --do things with thing
    end
}
game.ReplicatedStorage.ControlEvents.ShowEvent.OnServerEvent:Connect(function(plr,Show,Trigger)
    tableOfFunctions[Show](Trigger)
end)
0
This is exactly what I needed, thank you so much. My goal was to call forth a function inside a Server Script through a remote event. My function is the name of what gets triggered. Just2Terrify 566 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

If the function is a LocalScript, then do it like this: Change ur function to function _G.Show()

-- Click LocalScript

--//Made By MillerrIAm
local Event = game.ReplicatedStorage.ControlEvents.ShowEvent
--//Main Script
script.Parent.MouseButton1Click:Connect(function()
    _G.Show("Intro")
end)

-- function LocalScript

function _G.Show(Trigger)
   -- Your Script
end
0
I would NOT recommend using _G. Roblox actually recommends that you use ModuleScripts instead, as they can store dictionaries, functions, and variables. Also, you can store many things with module scripts. and are simpler to use in general. Dovydas1118 1495 — 3y
0
Okay WoGiTeam 60 — 3y
0
It isn't a local function, it's a server function that is triggered through the remote event. Just2Terrify 566 — 3y
0
If you wanna transfer functions, then just use a Module Script. You should only use parameters for variables and stuff. Also you can't use strings, you can only use values, like positions, BrickColor, etc. @MillerrIAm Dovydas1118 1495 — 3y
View all comments (2 more)
0
What do you mean when you say you can't use strings as a parameter? SteamG00B 1633 — 3y
0
I would like for you to refer to the answer I accepted, that will explain better of what I was looking for. Just2Terrify 566 — 3y

Answer this question