What do you want to achieve? Keep it simple and clear!
I want to know how to use a remote event or remote function once.
What is the issue? Include screenshots / videos if possible!
I don’t know how to assign specific parameters for each time I’m firing to that remote event/function.
Code
local UIS = game:GetService("UserInputService")
local CS = game:GetService("CollectionService")
local RS = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local debounce = false
--Player stats
local plr = players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local HRP = char.PrimaryPart
local hum = char:WaitForChild("Humanoid")
for i, v in pairs(CS:GetTagged("Wall")) do
v.Touched:Connect(function()
if not debounce then
debounce = true
local params = RaycastParams.new()
params.FilterDescendantsInstances = {char}
params.FilterType = Enum.RaycastFilterType.Exclude
local origin = HRP.Position
local direction = HRP.CFrame.LookVector * 3
local raycast = workspace:Raycast(origin,direction, params)
if raycast then
local attach = RS:WaitForChild("Climb"):InvokeServer("Touch")
if attach == true then
debounce = false
end
end
end
end)
end
local function movebutton(input)
if input.KeyCode == Enum.KeyCode.W or Enum.KeyCode.A or Enum.KeyCode.S or Enum.KeyCode.D then
local controlstable = {
W = HRP.CFrame.UpVector * 16,
S = HRP.CFrame.UpVector * -16,
A = HRP.CFrame.RightVector * 16,
D = HRP.CFrame.RightVector * -16,
}
local control = controlstable[input.KeyCode.Name]
RS:WaitForChild("Climb"):InvokeServer("Move",control)
end
end
local function stop(input)
if input.KeyCode == Enum.KeyCode.W or Enum.KeyCode.A or Enum.KeyCode.S or Enum.KeyCode.D then
RS:WaitForChild("Climb"):InvokeServer("Stop")
end
end
UIS.InputBegan:Connect(movebutton)
UIS.InputEnded:Connect(stop)
In here you can see 3 functions being fired to the server and 1 having an extra parameter. The problem is when that parameter runs, it turns out as nil.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried using more if statements but I’ve never tried to make a game with one remote event/function.
Keep in mind the 1st parameter passed is always the player. So no matter what you call it … in this case input that will be the player … you want (player, input) even if you’re not going to use player for anything.
local RS = game:GetService("ReplicatedStorage")
local runservice = game:GetService("RunService")
--Modules
local wallclimb = require(RS.WallClimb)
RS:WaitForChild("Climb").OnServerInvoke = function(plr, identifier, identifier2)
local char = plr.Character or plr.CharacterAdded:Wait()
local HRP = char.PrimaryPart
local hum = char:WaitForChild("Humanoid")
if identifier == "Touch" then
hum.AutoRotate = false
return true
elseif identifier == "Move" and identifier2 ~= "Nil" then
wallclimb.move(char,HRP,identifier2)
elseif identifier == "Stop" then
wallclimb.stop(char)
end
end
Ill send the message i was writing anyways:
Alright, so here the error isnt on the remotefunction, the first mistake ive notice, is on the conditional “if”, this conditional works like this: if true or true or true, so the correct way of using it would be this; if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.D then
also how you are accesing the table seems like an incorrect way. You can try this:
local controlstable = {
[Enum.KeyCode.W] = HRP.CFrame.LookVector * 16, -- Assuming forward direction
[Enum.KeyCode.S] = HRP.CFrame.LookVector * -16, -- Assuming backward direction
[Enum.KeyCode.A] = HRP.CFrame.RightVector * -16, -- Assuming left direction
[Enum.KeyCode.D] = HRP.CFrame.RightVector * 16, -- Assuming right direction
}
local control = controlstable[input.KeyCode]
RS:WaitForChild("Climb"):InvokeServer("Move