Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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

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. Mayk728 855 — 7y
0
Yeah but I want the GUI to pop up while the player jumps lol LukeGabrieI 73 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
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!

Ad

Answer this question