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

How can i convert this client sided script into server side?

Asked by
5qfb -8
4 years ago

Hi so i have this local script inside of a GUI. I'm trying to make an among us style game, but the kill gui does not work properly. When the imposter kills, it only happens on the imposter screen also known as client sided. I don't have much experience with making stuff server side, as I usually build and make UIs. If you can provide how you would do it, thank you.

local gui = script.Parent
local players = game:GetService("Players")
local player = players.LocalPlayer
local run = game:GetService("RunService")
local sound = script.KillSound


gui.KillButton.MouseButton1Click:Connect(function()
local character = player.Character
if not character then return end
local head = character:FindFirstChild("Head")
if not head then return end
for _, v in pairs(workspace:GetChildren()) do
    if v:IsA("Model") and v:FindFirstChild("Humanoid") and v:FindFirstChild("Head") and v ~= character then

        if (character.Head.Position - v.Head.Position).Magnitude <= 20 and v.Humanoid.Health > 0 and script.Parent.KillButton.Timer.Visible == false then
            sound:Play()
            v.Humanoid.Health = 0
            character:MoveTo(v.HumanoidRootPart.Position)
            script.Parent.KillButton.Timer.Visible = true
            script.Parent.KillButton.Timer.Text = "10"
            wait(1)
            script.Parent.KillButton.Timer.Text = "9"
            wait(1)
            script.Parent.KillButton.Timer.Text = "8"
            wait(1)
            script.Parent.KillButton.Timer.Text = "7"
            wait(1)
            script.Parent.KillButton.Timer.Text = "6"
            wait(1)
            script.Parent.KillButton.Timer.Text = "5"
            wait(1)
            script.Parent.KillButton.Timer.Text = "4"
            wait(1)
            script.Parent.KillButton.Timer.Text = "3"
            wait(1)
            script.Parent.KillButton.Timer.Text = "2"
            wait(1)
            script.Parent.KillButton.Timer.Text = "1"
            wait(1)
            script.Parent.KillButton.Timer.Visible = false
            break
        end
    end
end
end)

run.Heartbeat:Connect(function()
local character = player.Character
if not character then return end
local head = character:FindFirstChild("Head")
if not head then return end
local cankill = false
for _, v in pairs(workspace:GetChildren()) do
    if v:IsA("Model") and v:FindFirstChild("Humanoid") and v:FindFirstChild("Head") and v ~= character then

        if (character.Head.Position - v.Head.Position).Magnitude <= 20 and v.Humanoid.Health > 0 and script.Parent.KillButton.Timer.Visible == false then cankill = true end
        end
    end
    if cankill then
        gui.KillButton.ImageTransparency = 0
    else
        gui.KillButton.ImageTransparency = 0.65
    end
    end)
0
for your timer I suggest using a for loop. Such as: for i = 10,0,-1 do Text = i wait(1) end. Also I don't really have much time to answer the question yet but in order for you to do this do some research on RemoteEvents :) AntoninFearless 622 — 4y
0
First of all, use a for loop. That's why it exists. Secondly, just use FireServer() and use the 1st parameter (which is the player.) You can immediately use the Character and the Humanoid once you use the OnServerEvent. Dovydas1118 1495 — 4y
0
thank you. i will do some research on remoteevents 5qfb -8 — 4y
0
you know how much times you posted this question :/ ive already answered it giving you all scripts CrazyCats84 154 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

What I would do is, wait for the button to be pressed from the Impostor, use a RemoteEvent to tell the server who their target is, check if the target is close enough and then do the kill. I would then fire to both clients (with a RemoteEvent), receiving the call with RemoteEvent.OnClientEvent and then I would display the Kill GUI and hide it after the appropriate amount of time.

Ad
Log in to vote
0
Answered by 4 years ago

When answering, if your answer does not fully solve the question, it should be written as a comment to the question instead of as an answer.

you have posted the same question around 3 times, here is the answer again:

i remember the comment last time, so in a local script, your meant to use:

game.Players.LocalPlayer to get the local player

LocalScript:

gui = Game.Players.LocalPlayer.PlayerGui["Name"] -- what went wrong
local players = game:GetService("Players")
local player = players.LocalPlayer
local run = game:GetService("RunService")


gui.KillButton.MouseButton1Click:Connect(function()
    gui.RemoteEvent:FireServer(player,gui) -- Carry over the player and gui variable
end)

run.Heartbeat:Connect(function()
    gui.RemoteEvent2:FireServer(player,gui) -- Different Remote ok?
end)

FIRE THE REMOTEFUNCTION

ServerScript:

local sound = script.KillSound


gui.RemoteEvent.OnServerEvent:Connect(function(player,gui)  -- Player variable used
    local character = player.Character
    if not character then return end
    local head = character:FindFirstChild("Head")
    if not head then return end
    for _, v in pairs(workspace:GetChildren()) do
        if v:IsA("Model") and v:FindFirstChild("Humanoid") and v:FindFirstChild("Head") and v ~= character then

            if (character.Head.Position - v.Head.Position).Magnitude <= 20 and      v.Humanoid.Health > 0 and script.Parent.KillButton.Timer.Visible == false then
                sound:Play()
                v.Humanoid.Health = 0
                character:MoveTo(v.HumanoidRootPart.Position)
                script.Parent.KillButton.Timer.Visible = true
                wait(1)
                script.Parent.KillButton.Timer.Text = "9"
                wait(1)
                script.Parent.KillButton.Timer.Text = "8"
                wait(1)
                script.Parent.KillButton.Timer.Text = "7"
                wait(1)
                script.Parent.KillButton.Timer.Text = "6"
                wait(1)
                script.Parent.KillButton.Timer.Text = "5"
                wait(1)
                script.Parent.KillButton.Timer.Text = "4"
                wait(1)
                script.Parent.KillButton.Timer.Text = "3"
                wait(1)
                script.Parent.KillButton.Timer.Text = "2"
                wait(1)
                script.Parent.KillButton.Timer.Text = "1"
                wait(1)
                script.Parent.KillButton.Timer.Visible = false
                break
            end
        end
    end
end)

gui.RemoteEvent2.OnServerEvent:Connect(function(player,gui)
    local character = player.Character
    if not character then return end
    local head = character:FindFirstChild("Head")
    if not head then return end
    local cankill = false
    for _, v in pairs(workspace:GetChildren()) do
        if v:IsA("Model") and v:FindFirstChild("Humanoid") and          v:FindFirstChild("Head") and    v ~= character then

            if (character.Head.Position - v.Head.Position).Magnitude <= 20 and v.Humanoid.Health > 0 and script.Parent.KillButton.Timer.Visible == false then cankill = true end
        end
    end
    if cankill then
        gui.KillButton.ImageTransparency = 0
    else
        gui.KillButton.ImageTransparency = 0.65
    end
end)

This is why remote events are the best thing, unless you can enable FilteringEnabled for easier but unsafe scripting

0
ive tried and it does not work. 5qfb -8 — 4y
0
i will try to find a solution 5qfb -8 — 4y

Answer this question