What's wrong with my script?

So my script was intended to increase a player’s jump every time they pressed space but its not working with my script i wonder what’s wrong with it

1 Like

I kinda cannot read it, maybe copy the script and post it here, but put three ` on top and on the bottom so it looks like a script

Example

I will get a script from my game and post it here so you know what it looks like

Example

local Players = game:GetService(“Players”)
local UserInputService = game:GetService(“UserInputService”)

Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyPressed = input.KeyCode
elseif input.UserInputType == Enum.KeyCode.Space then
char.Humanoid.JumpPower = char.Humanoid.JumpPower + 100
print(“Jumped”)
end
end)
end)
end)

No no no, put three ` (Left side of the “1” key on your keyboard) on top and on bottom of the script
Here is the script from my game that enables bubble chat

local ChatService = game:GetService("Chat") 
ChatService:RegisterChatCallback(Enum.ChatCallbackType.OnCreatingChatWindow, function()
	return {BubbleChatEnabled = true}
end)
1 Like

So first of all, for future reference, please copy and paste your code in code format instead of a screenshot

Second of all, i would put right after the input connection that “if not gameProcessed then”…

You may be able to fix it by using a local variable rather than jumppower

I dont think player added can be called from a local script. It is unecessary in this situtation and because of the fact it is a client sided script it wont replicate to the server meaning it wont change the speed. in order to do this you will need a remote event. dont forget to mark this as a solution :slight_smile:

1 Like

Hold on I will get a picture of what you are supposed to do

1 Like

Capture
(I used the script I used above for an example)

’ ’ ’
local Players = game:GetService(“Players”)
local UserInputService = game:GetService(“UserInputService”)

Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyPressed = input.KeyCode
elseif input.UserInputType == Enum.KeyCode.Space then
char.Humanoid.JumpPower = char.Humanoid.JumpPower + 100
print(“Jumped”)
end
end)
end)
end)
’ ’ ’


Put three of the highlighted key (lowercase) on top of the script, and on the bottom
@sktvladimir535

`
local Players = game:GetService(“Players”)
local UserInputService = game:GetService(“UserInputService”)

Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyPressed = input.KeyCode
elseif input.UserInputType == Enum.KeyCode.Space then
char.Humanoid.JumpPower = char.Humanoid.JumpPower + 100
print(“Jumped”)
end
end)
end)
end)

`

like this?

You, you need three ` and like you put those there

i did but only one appeared

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		UserInputService.InputBegan:Connect(function(input, gameProcessed)
		if input.UserInputType == Enum.UserInputType.Keyboard then
		local keyPressed = input.KeyCode
		elseif input.UserInputType == Enum.KeyCode.Space then
		char.Humanoid.JumpPower = char.Humanoid.JumpPower + 100
		print("Jumped")
	end
		end)
	end)
end)

oh nc

There you go that’s better, now I recommend putting one message at the solution and making a new topic because this one is filled with teaching you how to write like code in studio, but you do not have to if you do not want to

1 Like

did you see my suggestion? I recommend using remote events since this is client sided hence wny changes to players local speed will do nothing so you will need to do remote events and change the speed in the server instead

how i don’t know how to use remote events

I recommend reading this articles as client server communication is key to roblox development. I recommend learing the client server model and then the remote functions. Dont forget to mark this as a solution.

Client-Server Model ^

Remote Events/Functions ^

1 Like

PlayerAdded doesn’t fire for the current player, so your functions aren’t getting connected for the current player. What this script will actually do is every time another player joins and every time they spawn in, a new InputBegan connection will spawn up. You’re going to run into some very major problems.

You can work towards fixing this by getting rid of PlayerAdded and CharacterAdded entirely. Don’t include either of those, you don’t want to use them. Now to access the character variable, look for the LocalPlayer’s character and then you’re set.

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()