Although I have not fully learned LUA coding, I am kinda grasping the concept. I have been working hours on a single line of code that, no matter what, brings up as " 18:47:07.519 - attempt to call a nil value" I cannot STAND this single error code. To attempt to solve the problem, I have set up two print lines; one in the local script and one in the normal script. The local print works but the normal script doesn't print.
--local local UIS = game:GetService('UserInputService') local plr = game.Players.LocalPlayer local Char = plr.Character or plr.CharacterAdded:Wait() local key = 'L' local Anim = Instance.new("Animation") Anim.AnimationId = 'rbxassetid://4906894017' local Debounce = true UIS.InputBegan:Connect (function(Input, IsTyping) if IsTyping then return end local KeyPressed = Input.KeyCode if KeyPressed == Enum.KeyCode.L and Debounce then Debounce = false local LoadAnimation = Char.Humanoid:LoadAnimation(Anim) LoadAnimation:play() print("The Crimson God Has Been Summoned; Run...") game.ReplicatedStorage.Summon:FireServer(print"Event Has Fired") end end) --Script (In Workspace if that helps) game.ReplicatedStorage.Summon.OnServerEvent:Connect(print"Message has been received")
Your code doesn't work because :FireServer()
and :Connect()
are not being used correctly.
:FireServer()
takes a value or expression to pass to the event. In your case, print"Event Has Fired"
runs and prints to the console, but evaluates to nil and is not passed to the event.
:Connect()
takes in a function to be called when the event is fired. For an event where the server is fired, the first argument to the function will be the player, followed by any arguments passed to :FireServer()
This can be done in two ways, the first being with a named function:
function doStuff(player, myText) print(myText) -- Other code goes here end RemoteEvent.OnServerEvent:Connect(doStuff)
And the second is an anonymous function:
RemoteEvent.OnServerEvent:Connect(function(player, myText) print(myText) -- Other code goes here end)
Both are functionally identical, but the named function is more readable and allows you to call the function from somwhere other than the event.
You would fire this event from a LocalScript with the following:
RemoteEvent:FireServer(myText)