Having trouble getting Character on server side

I have a relatively simple script that, will, when you buy a developer product, grant you the abilities.

My script doesn’t work for some reason, in studio it will work, but it doesn’t ever work in an actual game. The lines that error in this script are marked with an error comment to the side

MarketplaceService.ProcessReceipt = function(recietInfo)
	if recietInfo.ProductId == 1278432013 then -- walk
		local Player = Players:GetPlayerByUserId(recietInfo.PlayerId)
		Player.Walk.Value = true
		Player.Character:WaitForChild("Humanoid").WalkSpeed=16-- errors
	elseif recietInfo.ProductId == 1278432012 then -- jump 
		local Player = Players:GetPlayerByUserId(recietInfo.PlayerId)
		Player.Jump.Value = true
		Player.Character:WaitForChild("Humanoid").UseJumpPower=true -- errors
		Player.Character.Humanoid.JumpPower = 50
	elseif recietInfo.ProductId == 1278432011 then -- chat
		local Player = Players:GetPlayerByUserId(recietInfo.PlayerId)
		Player.Chat.Value = true
		Player.ChatsLeft.Value = 5
	end
end

Works in studio usually, but doesn’t always work in a server. This script is located in SSS as a Script.

The message I get is:

Maybe add an extra if statement checking to make sure that the player exists, as well, checking if the character isn’t nil before changing the Humanoid Properties. See if that could help.

The character is not a child of the player. You can find the character from the player’s property section.

1 Like

You’re right. I’m just stupid.

it’s been a while since I’ve done this

1 Like

Something like this, fix my indentation I’m on mobile lol.

MarketplaceService.ProcessReceipt = function(recietInfo)
	if recietInfo.ProductId == 1278432013 then -- walk
		local Player = Players:GetPlayerByUserId(recietInfo.PlayerId)
		Player.Walk.Value = true
        if Player.Character ~= nil then
		    character = Player.Character
            character:WaitForChild("Humanoid").WalkSpeed=16-- errors
	elseif recietInfo.ProductId == 1278432012 then -- jump 
		local Player = Players:GetPlayerByUserId(recietInfo.PlayerId)
		Player.Jump.Value = true
        if Player.Character ~= nil then
		     character = Player.Character
             character:WaitForChild("Humanoid").UseJumpPower=true -- errors
		     Player.Character.Humanoid.JumpPower = 50
	elseif recietInfo.ProductId == 1278432011 then -- chat
		local Player = Players:GetPlayerByUserId(recietInfo.PlayerId)
		Player.Chat.Value = true
		Player.ChatsLeft.Value = 5
	end
end
1 Like
game.Players.PlayerAdded:Connect(function(Player)
        MarketplaceService.ProcessReceipt = function(recietInfo)
	if recietInfo.ProductId == 1278432013 then -- walk
		local Player = Players:GetPlayerByUserId(recietInfo.PlayerId)
		Player.Walk.Value = true
		Player.Character:WaitForChild("Humanoid").WalkSpeed=16-- errors
	elseif recietInfo.ProductId == 1278432012 then -- jump 
		local Player = Players:GetPlayerByUserId(recietInfo.PlayerId)
		Player.Jump.Value = true
		Player.Character:WaitForChild("Humanoid").UseJumpPower=true -- errors
		Player.Character.Humanoid.JumpPower = 50
	elseif recietInfo.ProductId == 1278432011 then -- chat
		local Player = Players:GetPlayerByUserId(recietInfo.PlayerId)
		Player.Chat.Value = true
		Player.ChatsLeft.Value = 5
	end
end
end)

not sure if it works

That would cause a logical error I believe. Not positive don’t have studio on my phone :joy:

I’ve had this issue myself too alot of the times and I think I know how to fix it, here try this:

oh and I should also address it that its good to add a if statement for character, you can add it if you want

MarketplaceService.ProcessReceipt = function(recietInfo)
	if recietInfo.ProductId == 1278432013 then -- walk
		local Player = game.Players:GetPlayerByUserId(recietInfo.PlayerId)
		local Character = game.Workspace:WaitForChild(Player.Name)
		Player.Walk.Value = true
		Character:WaitForChild("Humanoid").WalkSpeed=16-- errors
	elseif recietInfo.ProductId == 1278432012 then -- jump 
		local Player = game.Players:GetPlayerByUserId(recietInfo.PlayerId)
		local Character = game.Workspace:WaitForChild(Player.Name)
		Player.Jump.Value = true
		Character :WaitForChild("Humanoid").UseJumpPower=true -- errors
		Character .Humanoid.JumpPower = 50
	elseif recietInfo.ProductId == 1278432011 then -- chat
		local Player = game.Players:GetPlayerByUserId(recietInfo.PlayerId)
		Player.Chat.Value = true
		Player.ChatsLeft.Value = 5
	end
end

Where do I put the if statement for the character? I tried putting an if character on both after defining the Character but that breaks it entirely

MarketplaceService.ProcessReceipt = function(recietInfo)
    local Player = game.Players:GetPlayerByUserId(recietInfo.PlayerId)
	local Character = game.Workspace:WaitForChild(Player)
	if recietInfo.ProductId == 1278432013 then -- walk
		Player.Walk.Value = true
		Character:WaitForChild("Humanoid").WalkSpeed=16-- errors
	elseif recietInfo.ProductId == 1278432012 then -- jump 
		Player.Jump.Value = true
		Character :WaitForChild("Humanoid").UseJumpPower=true -- errors
		Character .Humanoid.JumpPower = 50
	elseif recietInfo.ProductId == 1278432011 then -- chat
		Player.Chat.Value = true
		Player.ChatsLeft.Value = 5
	end
end

Not sure if this will work … but, your error is within these two lines. It’s not returning the Character.
Focus in on that part of the script. To make sure it’s returning the correct value I added a print(Character) check.

local Player = game.Players:GetPlayerByUserId(recietInfo.PlayerId)
local Character = game.Workspace:WaitForChild(Player.Name)

Also there is no need to put that in every if…
Some other guesses …

local Character = game.Workspace:WaitForChild(tostring(Player.Name))
local Character = Player.Character  

That last version is normally how you would do that.

1 Like

@Lorourkethebest it’s been a few days since you have not replied to any of the posts above. Have you solved this issue yet? If you have, could you please let us know

1 Like

Well, I solved the issue, but my code is still messing up. (Not related to this)

Mods, you can go ahead and close this now.

1 Like