FireServer() Doesn't fire the remote event - lua

i was making a script that changes a value when the player dies, i did it with remote events but it didn't work.
Local Script:
local plr = game:GetService('Players').LocalPlayer
wait(2)
local char = plr.Character
local humanoid = char:WaitForChild("Humanoid")
humanoid.Died:Connect(function(death)
print('death')
game:GetService('ReplicatedStorage').setPlayerInLobby:FireServer()
print('fired')
end)
Server script:
rs.setPlayerInLobby.OnServerEvent:Connect(function(plr)
print("works i guess?")
plr.InLobby.Value = true
end)
It printed out "death" and "fired" but it didn't do anything else.

You never defined the rs variable in your server Script.
local rs = game:GetService("ReplicatedStorage")

local plr = game:GetService('Players').LocalPlayer
local char = plr.Character
local humanoid = char:WaitForChild("Humanoid")
if plr.Character.Humanoid.Health == 0 then
print("Bla bla")
end
So you can use it on a local script i guess

Related

"attepted to index nil with Humanoid"

local animationstomp = script.Animation
local user = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = player.Character
local human = char.Humanoid
user.InputBegan:Connect(function(input, proccesedevent)
if input.KeyCode == Enum.KeyCode.F then
local animationtrack = human:LoadAnimation(animationstomp)
animationtrack:play()
end
end
end)
this script keeps returning error "attempted to index nil with huamnoid" i have looked for solutions on dev forum and on stack overflow but i could not find anything so im going to post myself. anyone catch any erros?
"attempted to index nil with huamnoid"
What that means is that this script loaded before the player's character loaded in.
To fix this, you can use
local char = player.Character or player.CharacterAdded:Wait()
-- uses the player if it's already loaded in, or waits for the character to load in
Also make sure to use
local human = char:WaitForChild("Humanoid")
-- to make sure you wait till the humanoid gets added
Final script
local animationstomp = script.Animation
local user = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local human = char:WaitForChild("Humanoid")
user.InputBegan:Connect(function(input, proccesedevent)
if input.KeyCode == Enum.KeyCode.F then
local animationtrack = human:LoadAnimation(animationstomp)
animationtrack:play()
end
end)

Check if tool is equipped

How do I determine in a condition if a tool is currently equipped?
The following is the LocalScript in my tool, called "Axe".
local UIS = game:GetService("UserInputService")
local Animation = script.Chop
local Player = game.Players.LocalPlayer
local Character = Player.Character
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local A = Humanoid:LoadAnimation(Animation)
A:Play()
end
end)
Tools are parented under the character when equipped. Henceforth, you can just write the following condition:
if Player.Character:FindFirstChild("Axe") ~= nil then
you can make a variable that can store a boolean and changes when the tool is equipped or unequipped
local isEquipped = false
Tool.Equipped:Connect(function()
isEquipped = true
end)
Tool.Unequipped:Connect(function()
isEquipped = false
end)

attempt to index nil with 'LoadCharacter'

When trying to respawn the player with plr:LoadCharacter() it just gives me:
attempt to index nil with 'LoadCharacter' & I tried multiple ways to do it such as Player:LoadCharacter() or is there a more efficient way to kill/respawn the player?
--Declared Boolean Global variable
_G.TimerStart = false
--Local Paths to Objeccts
local label = game.StarterGui.TimerGUI.Timer
-- Get Service Variables
local Teams = game:GetService("Teams")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local plr = game:GetService("Players").LocalPlayer
--Get Children
local Child = game.Players:GetChildren()
-- Wait for Child Variables
local TimeCountdown = ReplicatedStorage:WaitForChild("Timer")
local timerevent = ReplicatedStorage:WaitForChild("Timer")
local function Thieves(Players)
if _G.TimerStart == false then
for i,v in pairs(game.Teams.Thieves:GetPlayers()) do
game.StarterGui.ThiefWinScreen.Frame.TextLabel.Script.Disabled = false
wait(2)
plr:LoadCharacter()
wait(7)
timerAmount = 120
end
for i,v in pairs(game.Teams.Police:GetPlayers()) do
game.StarterGui.ThiefWinScreen.Frame.TextLabel.Script.Disabled = false
wait(2)
plr:LoadCharacter()
wait(7)
timerAmount = 120
end
end
end
In this case plr is a nil value. So plr:LoadCharacter() is not allowed as it does not make any sense.
local plr = game:GetService("Players").LocalPlayer
is the reason.
So refer to this manual page: https://developer.roblox.com/en-us/api-reference/property/Players/LocalPlayer
Maybe this helps:
Loading GUIs When creating loading GUIs using ReplicatedFirst, sometimes a LocalScript can run before the LocalPlayer is available.
In this case, you should yield until it becomes available by using
Instance:GetPropertyChangedSignal
local Players = game:GetService("Players")
-- Below: access Players.LocalPlayer; if it is nil, we'll wait for it using GetPropertyChangedSignal.
local player = Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):wait()

Debounce is not a valid member of Folder

Alright so I got this script from a tutorial and this is what I typed for the script Remotes
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
local cooldown = 1
replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
print("event launched")
if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
local debounce = remoteData[player.Name].Debounce
if not debounce then
debounce.Value = true
player.leaderstats.Power.Value = player.leaderstats.Power.Value + 5 * (player.leaderstats.Prestiges.Value + 1)
wait(cooldown)
debounce.Value = false
end
end)
but I have seem to get the error which is
Debounce is not a valid member of Folder "ServerStorage.RemoteData.OmegaHero2010"
here are some other scripts
Stats
local serverStorage = game:GetService("ServerStorage")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local power = Instance.new("NumberValue")
power.Name = "Power"
power.Parent = leaderstats
local prestige = Instance.new("NumberValue")
prestige.Name = "Prestiges"
prestige.Parent = leaderstats
local dataFolder = Instance.new("Folder")
dataFolder.Name = player.Name
dataFolder.Parent = serverStorage.RemoteData
local debounce = Instance.new("BoolValue")
debounce.Parent = dataFolder
end)
Module
local module = {}
local replicatedStorage = game:GetService("ReplicatedStorage")
function module.Lift()
replicatedStorage.Remotes.Lift:FireServer()
end
return module
Local Script
local module = require(script.Parent:WaitForChild("ModuleScript"))
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Activated:Connect(function()
module.Lift()
end)
what is the problem here?
The line local debounce = remoteData[player.Name].Debounce is failing to find the child named "Debounce".
So, looking at how you created the BoolValue in ServerScriptService :
local debounce = Instance.new("BoolValue")
debounce.Parent = dataFolder
You never set the Name property. So there is a BoolValue in the player's folder but it is named "BoolValue", not "Debounce". To fix your error, just add the line to set the Name.
debounce.Name = "Debounce"

Leaderstats not working? or just not detecting the click?

I am trying to make a Simulator game on Roblox but I just can't seem to get the leader stats to work or it does work and my click event thing doesn't work, I am just following a tutorial for the scripting so I have no clue. This is my Remotes script where it says print("IS THIS WORKING") that was to see what was the problem. Basically that doesn't run or there's another problem that stops that from running, I think at least. I have other scripts and I will put some in that I think might be neccesary but if you need more feel free to ask me.
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
local cooldown = 1
print("IS THIS WORKING")
replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)
if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
local debounce = remoteData[player.Name].Debounce
if not debounce then
debounce.Value = true
player.leaderstats.Stealth.Value = player.leaderstats.Stealth.Value + 25 *(player.leaderstats.Rebirths.Value + 1)
wait(cooldown)
debounce.Value = false
end
Stats
local serverStorage = game:GetService("ServerStorage")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local stealth = Instance.new("NumberValue")
stealth.Name = "Stealth"
stealth.Parent = leaderstats
local rebirths = Instance.new("IntValue")
rebirths.Name = "Rebirths"
rebirths.Parent = leaderstats
local Folder = Instance.new("Folder")
Folder.Name = player.Name
Folder.Parent = serverStorage.RemoteData
local debounce = Instance.new("BoolValue")
debounce.Name = "Debounce"
debounce.Parent = Folder
end)
ModuleScript
local module = {}
local replicatedStorage = game:GetService("ReplicatedStorage")
function module.Lift()
replicatedStorage.Remotes.Lift:FireServer()
end
return module
LocalScript
local module = require(script.Parent:WaitForChild("ModuleScript"))
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Activated:Connect(function()
module.Lift()
end)
For my Explorer Structure click
here
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
your problem is when it waits for a child it yields the script until RemoteData is found
later in the script, it checks if RemoteData is nil or not
if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
two solutions:
first is to add a max wait for the yield so it will eventually stop if it can't find RemoteData (only useful is RemoteData is added after the script starts running)
second is the replace wait with FindFirstChild that will check immediately without waiting for it
the solution I recommend
local remoteData = game:GetService("ServerStorage"):FindFirstChild("RemoteData")
secondary solution if you have RemoteData added after the script starts and want to double-check
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData",20)
be sure to tell me is this works as I spent a while figuring it out

Resources