Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

character can't jump in a certain area script?

I made a giant cancollide transparent brick and I put this script in it

function onTouch() game.Players.PlayerAdded.Jump = false end

script.Parent.Touched:connect(onTouch)

I want to make it where once you get out of the transparent brick you can jump again so im guessing i would need to make an if then function? but im not sure.

also I don't know how i would identify the character that the person is playing as, and not everyone in the server

edit:

local script (in starterkit)

local remoteEvent = game.ReplicatedStorage:WaitForChild("ActivateTouch")
local Touchends = game.ReplicatedStorage:WaitForChild("Touchend")

--When Touched
remoteEvent.OnClientEvent:connect(function(player)
    player.Character.Humanoid.JumpPower = 0
end

--When Touchends
Touchends.OnClientEvent:connect(function()
    player.Character.Humanoid.JumpPower = 50
end

script (in workspace)

detecttouch = game.Workspace.nojump


--Create remote event on Touched to communicate between server and player scripts(client)
local RemoteEvent = instance.new("RemoteEvent")
RemoteEvent.Parent = game.WaitForChild("ReplicatedStorage")
RemoteEvent.Name = "ActivateTouch"

--Create remote event for TouchEnded
local RemoteEvent = instance.new("RemoteEvent")
Touchends.Parent = game.WaitForChild("ReplicatedStorage")
Touchends.Name = "Touchend"

--When Touched
detecttouch.Touched:connect(function(hit)
    --get the humanoid (This is how you find for humanoid with an Touched event)
    humanoid = hit.Parent.FindFirstChild("Humanoid")
    --Check for humanoid (Only found in players, so that other parts which touch this will not activate this script)
    if humanoid then
        local player = hit.Parent.GetPlayerFromCharacter()
        RemoteEvent:FireClient(player)
    end
end

--When Touch ends
detecttouch.TouchEnded:connect(function(hit)
    --Can't delete hit as these are two separate functions
    humanoid = hit.Parent.FindFirstChild("Humanoid")
    local player = hit.Parent.GetPlayerFromCharacter()
    Touchends:FireClient(player)
end

1 comment

0

Hi there, try out my answer, I do suggest you set filteringenabled to true.

1 answer

✓ Accepted answer

Hi there,

So, you would like a script that disables jumping in a part, however, based on your script above, when you set jump to false, the player is still able to jump as that option only can detect if a player is jumping, whereby when the player pressed spacebar, Jump will turn to true before turning back to false. Thus, in order to stop a player from jumping, you should use JumpPower. By default, the player can jump to a JumpPower of 50, So, setting the JumpPower to 0 will force the player to be unable to jump. Additionally, in order to make just a single player do it, you should write your script inside a local script and parent it under StarterPack. Since the StarterPack only loads when the player loads in, the script will only activate when the player joins the game.

If your game is to be not filtering enabled (In experimental mode), server scripts and local scripts will not be able to communicate with each other so I do suggest that you put a remote event such that when on Touch, activate the remote event to the local script.

So here is what your script should look like: I do suggest using filtering enabled to prevent hackers.

#1 If you don't have filtering enabled. Local script:

local detecttouch = game.Workspace.(Part detector's name)

--When Touched
detecttouch.Touched:connect(function(hit)
	--get the humanoid (This is how you find for humanoid with an Touched event)
	humanoid = hit.Parent.FindFirstChild("Humanoid")
	--Check for humanoid (Only found in players, so that other parts which touch this will not activate this script)
	if humanoid then
		humanoid.JumpPower = 0
	end
end

--When Touch ends, allow jumping
detecttouch.TouchEnded:connect(function(hit)
	--Can't delete hit as these are two separate functions
	humanoid = hit.Parent.FindFirstChild("Humanoid")
	--Reset to default
	humanoid.JumpPower = 50
end

#2 If you have filtering enabled Server script:

--Create remote event on Touched to communicate between server and player scripts(client)
local RemoteEvent = instance.new("RemoteEvent)
RemoteEvent.Parent = game.WaitForChild("ReplicatedStorage")
RemoteEvent.Name = "ActivateTouch"

--Create remote event for TouchEnded
local RemoteEvent = instance.new("RemoteEvent)
Touchends.Parent = game.WaitForChild("ReplicatedStorage")
Touchends.Name = "Touchend"

local detecttouch = game.Workspace.(Part detector's name)

--When Touched
detecttouch.Touched:connect(function(hit)
	--get the humanoid (This is how you find for humanoid with an Touched event)
	humanoid = hit.Parent.FindFirstChild("Humanoid")
	--Check for humanoid (Only found in players, so that other parts which touch this will not activate this script)
	if humanoid then
		local player = hit.Parent.GetPlayerFromCharacter()
		RemoteEvent:FireClient(player)
	end
end)

--When Touch ends
detecttouch.TouchEnded:connect(function(hit)
	--Can't delete hit as these are two separate functions
	humanoid = hit.Parent.FindFirstChild("Humanoid")
	local player = hit.Parent.GetPlayerFromCharacter()
	Touchends:FireClient(player)
end)

In localscript:

local remoteEvent = game.ReplicatedStorage:WaitForChild("ActivateTouch")
local Touchends = game.ReplicatedStorage:WaitForChild("Touchend")

--When Touched
remoteEvent.OnClientEvent:connect(function(player)
	player.Character.Humanoid.JumpPower = 0
end)

--When Touchends
Touchends.OnClientEvent:connect(function(player)
	player.Character.Humanoid.JumpPower = 50
end)

13 comments

0

wait, should i put the first script in the starterkit, then the localscript inside of the script?

0

You should put the local script into StarterPack and the normal script anywhere inside workspace.

0

ah, i think i did something wrong. on the 26th line in the script detecttouch is underlined in red, and on the 10th line in the local script touchends is underlined in red

0

Oh yes, I added a line: local detecttouch = game.Workspace.(Part detector's name) in the normal script. As for Touchends, I don''t seem to be able to spot any problems.

0

yes i added that line to the script but it still underlines it in red. i don't know

0

Could you re-edit your question with the new code you've typed? Be sure to put it in code blocks.

0

ok

0

i did

0

Hover your mouse over the detecttouch and Touchends which are in red, what does the error say?

0

Expected ')' to close '(' at line 15), got detecttouch

0

I've re-edited my answer, it should work now.

0

now player in the localscript is unknown

0

Sorry, my mistake! Try again.

This discussion is preserved as it was. New answers, comments, and votes are closed.