Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Why is my function not running at all?

Asked by 7 days 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
SteamG0D 1380 Moderation Voter
6 days ago
Edited 6 days 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. MillerrIAm 571 — 6d
Ad
Log in to vote
0
Answered by 7 days 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 727 — 7d
0
Okay WoGiTeam 45 — 7d
0
It isn't a local function, it's a server function that is triggered through the remote event. MillerrIAm 571 — 7d
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 727 — 7d
View all comments (2 more)
0
What do you mean when you say you can't use strings as a parameter? SteamG0D 1380 — 6d
0
I would like for you to refer to the answer I accepted, that will explain better of what I was looking for. MillerrIAm 571 — 6d

Answer this question