Ok so I’m a scripter with not that much experience and when “hit is not a valid member of players” I had no clue on what it was. I would really appreciate any help from you guys. Have a great day!!
Can you leave us a code sample of your script so we can see what the script is identifying “hit” as?
Seems you did an error with your touched event.
It’s basically saying that hit is not a child of players.
Well I don’t know where the error is because it only said that in the output and not the script analysis.
Show us the script so we can help you out even more.
local Players = game:GetService("Players")
local function newLeaderStatsFolder(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name ="leaderstats"
leaderstats.Parent = player
print("Done 3-7")
local experience = Instance.new("IntValue")
experience.Name = "Experience"
experience.Value = 0 --If you have a datastore then this would be where to connect the DataStore value
experience.Parent = leaderstats
print("Done 9-12")
local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 0 --DataStore save would go here
level.Parent = leaderstats
print("Done 15-18")
end
local function addExperienceToPlayer(hit)
print("Done 22")
local debounce = false
print("Done 24")
if hit.Parent:FindFirstChild("Humanoid") then
print("Done 26")
if Players:GetPlayerFromCharacter(hit) then
print("Done 28")
else
print("Player does not exist!")
if not debounce then
print("Done 32")
debounce = true
print("Done 34")
Players.hit.leaderstats.Value = Players.hit.leaderstats.Experience.Value + 25
print("Done 36")
debounce = false
print("Done 38")
end
end
end
end
Players.PlayerAdded:Connect(newLeaderStatsFolder)
game.Workspace.Part.Touched:Connect(addExperienceToPlayer)
print("Done 45-46")
Over there why are you doing an if statement? Just get the player instead since you found the character.
local Players = game:GetService("Players")
local function newLeaderStatsFolder(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name ="leaderstats"
leaderstats.Parent = player
print("Done 3-7")
local experience = Instance.new("IntValue")
experience.Name = "Experience"
experience.Value = 0 --If you have a datastore then this would be where to connect the DataStore value
experience.Parent = leaderstats
print("Done 9-12")
local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 0 --DataStore save would go here
level.Parent = leaderstats
print("Done 15-18")
end
local function addExperienceToPlayer(hit)
print("Done 22")
local debounce = false
print("Done 24")
if hit.Parent:FindFirstChild("Humanoid") then
print("Done 26")
if Players:GetPlayerFromCharacter(hit.Parent) then
print("Done 28")
else
print("Player does not exist!")
if not debounce then
print("Done 32")
debounce = true
print("Done 34")
Players.hit.leaderstats.Value = Players.hit.leaderstats.Experience.Value + 25
print("Done 36")
debounce = false
print("Done 38")
end
end
end
end
Players.PlayerAdded:Connect(newLeaderStatsFolder)
game.Workspace.Part.Touched:Connect(addExperienceToPlayer)
print("Done 45-46")
put a parent thats how the system works
Put parent where??? (30 characters)
i was wrong sorry but you need to define the parent i meant the player
local plr = Players:GetPlayerFromCharacter(hit.Parent)
Players.hit.leaderstats.Value = Players.hit.leaderstats.Experience.Value + 25
should be:
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
player.leaderstats.Experience.Value = player.leaderstats.Experience.Value + 25
end
local Players = game:GetService("Players")
local function newLeaderStatsFolder(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name ="leaderstats"
leaderstats.Parent = player
print("Done 3-7")
local experience = Instance.new("IntValue")
experience.Name = "Experience"
experience.Value = 0 --If you have a datastore then this would be where to connect the DataStore value
experience.Parent = leaderstats
print("Done 9-12")
local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 0 --DataStore save would go here
level.Parent = leaderstats
print("Done 15-18")
end
local function addExperienceToPlayer(hit)
print("Done 22")
local debounce = false
print("Done 24")
if hit.Parent:FindFirstChild("Humanoid") then
print("Done 26")
if Players:GetPlayerFromCharacter(hit.Parent) then
local plr = Players:GetPlayerFromCharacter(hit.Parent)
print("Done 28")
else
print("Player does not exist!")
if not debounce then
print("Done 32")
debounce = true
print("Done 34")
plr.leaderstats.Value = plr.leaderstats.Experience.Value + 25
print("Done 36")
debounce = false
print("Done 38")
end
end
end
end
Players.PlayerAdded:Connect(newLeaderStatsFolder)
game.Workspace.Part.Touched:Connect(addExperienceToPlayer)
print("Done 45-46")
Should Work
Actually you have to put local plr = game.Players otherwise it won’t work.
player service does GetPlayerFromCharacter
but game.Players wont work
And the code above should work
Really close but the code stops functioning at line 28. Thanks though!
I cleaned up your touched function:
local debounce = false;
local function onTouched(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent);
local hum = part.Parent:FindFirstChild("Humanoid");
local sucess = (hum and player) and true or nil;
if not debounce then
debounce = true;
if sucess and hum.Health>0 then
local ls = player:FindFirstChild("leaderstats");
if ls then
local EXP = ls:FindFirstChild("Experience");
if EXP then
EXP.Value = EXP.Value + 25 ;
end
end;
end;
wait(5);
debounce = false;
end;
end;
game.Workspace.Part.Touched:Connect(onTouched)
I believe you defined players by this? We dont have your code so its hard to determine but.
game.Players:FindFirstChild("hit")
Was it something like that?
Personally when I try to get hit I make a function like so:
function whatever(hit)
hit.Parent
end)
Thanks! (30 char)
It only works with a part in the workspace, but thank you so much for your effort.