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

How-To Get this Script to Work in a Server instead of Client?

I basically have this script where whenever a player jumps, it'll toggle some text on the top of the screen. It'll say "Jump when you are ready" then when someone jumps, it'll toggle "Shoot!". Basically, it'll give someone an idea when to release the tool after a given number of seconds.

Here's the script, it basically deals with humanoids and their jump functions.

Local Script

local player = game.Players.LocalPlayer
local character = player.Character

repeat wait() until character

humanoid = character:WaitForChild("Humanoid")

local label = script.Parent
local debounce = true

local playergui = player:WaitForChild("PlayerGui")
local lukemode = playergui:WaitForChild("LukeMode")
local value = lukemode:WaitForChild("Value")

humanoid.Changed:connect(function()
	if humanoid.Jump == true then
		if debounce then
		debounce = false
		if value.Value == true then
		wait(0.2)
		else
		wait(0.35)
		end
		label.Text = "Shoot!"
		wait(1)
		label.Text = "Cooldown.."
		debounce = true
		wait(1)
		label.Text = "Jump when you are ready."
		end
	end
end)

Now this doesn't work when it's in server-side, which I tried to attempt down below.

Attempted Server Side:

local debounce = true

function onTouched(hit)
	if hit.Name == "VBL_Ball" or hit.Parent:IsA("Tool") then
		wait()
	else
	local character = hit.Parent
	print("character found")
	local player = game.Players:GetPlayerFromCharacter(character)
	print("player found")
	local humanoid = character:WaitForChild("Humanoid")
	print("humanoid found")
	local gui = player:WaitForChild("PlayerGui")
	print("gui found")
	local screen = gui:WaitForChild("ScreenGui")
	print("screen found")
	local frame = screen:WaitForChild("Frame")
	print("frame found")
	local label = frame:WaitForChild("TextLabel")
	print("label found")
	local lukemode = gui:WaitForChild("LukeMode")
	print("lukemode found")
	local value = lukemode:WaitForChild("Value")
	print("value found")
	humanoid.Changed:connect(function()
		print("humanoid changed")
		humanoid.Jumping:connect(function()
		print("humanoid jumping")
		if humanoid.Jump == true then
		print("humanoid jump")
		if debounce then
		debounce = false
		if value.Value == true then
		wait(0.2)
		else
		wait(0.35)
		end
		label.Text = "Shoot!"
		wait(1)
		label.Text = "Cooldown.."
		debounce = true
		wait(1)
		label.Text = "Jump when you are ready."
		end
	end
	end)
	end)
	end
end

script.Parent.Touched:connect(onTouched)

What's Suppose to Happen in the End (Only works in Client):

GIF

Hopefully you guys can figure out a solution to my problem.

Sincerely,

LukeGabrieI

3 comments

1

You're not supposed to be using ServerScripts in StarterGui. Why would you want to convert it to a ServerScript anyway, it works fine as-is.

0

Yeah but I want the GUI to pop up while the player jumps lol

1 answer

✓ Accepted answer
local debounce = true

game.Players.PlayerAdded:connect(function(player) --I'm going to use the PlayerAdded event in order to get player
	player.CharacterAdded:connect(function(character)
		
		local humanoid = character:WaitForChild("Humanoid")
		local pgui = player:WaitForChild("PlayerGui")
		local screen = pgui:WaitForChild("Screen")
		local frame = screen:WaitForChild("Frame")
		local label = frame:WaitForChild("TextLabel")
		local lukemode = pgui:WaitForChild("LukeMode")
		local value = lukemode:WaitForChild("Value")
		
		humanoid.Changed:connect(function()
			if humanoid.Jump == true then
				if debounce then
					debounce = false
					if value.Value == true then
						wait(0.2)
					else
						wait(0.35)
					end
					
					label.Text = "Shoot!"
					wait(1)
					label.Text = "Cooldown.."
					debounce = true
					wait(1)
					label.Text = "Jump when you are ready"
				end
			end
		end)
		
	end)
end)

I have this in a script inside of ServerScriptService. I'm not sure if this is what you're looking for but I hope it can help you out anyways!

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