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

How do I make this server side instead of client side? [closed]

Asked by
5qfb -8
4 years ago
Edited 4 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.
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
            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)

Edit By JesseSong:

Please do not use deceitful means to get users to do your request. If you want to pay people to help you with your code you should make a portfolio in the Roblox Developer forums.

Make sure your question is paraphrased with a sentence explaining what is wrong and not working with the code. You can click on the hyperlink provided

Closed as Non-Descriptive by JesseSong

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

This might not work, but oh well lets give this a try,

LocalScript:

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


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

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

FIRE THE REMOTEFUNCTION

ServerScript:

gui = script.Parent
local sound = script.KillSound


gui.RemoteEvent.OnServerEvent:Connect(function(player)  -- 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)
    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
if this doesnt work then make sure you use the example above to adapt and learn C: CrazyCats84 154 — 4y
0
the gui part does not work as the script parent is sss instead of the gui. im not sure if this workbut what if i do "player.PlayerGui.GUI" 5qfb -8 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 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.

Is this a GUI among us style kill button? Because you can't make GUI on server. You need to send a function from the client to the server then code the server. You will need a Remote event in Rep. Storage and code it so that when you press the GUI button it runs FireServer() I think that is what you were looking for? let me know if you have any questions

Here's what I would do

-- On the client

script.Parent.MouseButton1Click:Connect(function() --When you click the button
    game.ReplicatedStorage.Kill:FireServer()--Run the server
end)
--On the Server
game.ReplicatedStorage.Kill.OnServerEvent:Connect(function()
    --Put your code in here and have a good day :)
end)
0
yes it is 5qfb -8 — 4y
0
Ui and GUI is client-only. You could, however, use remote events to make this go from client to server. Mrdirtbloc -9 — 4y
0
i dont know how remote events work so if u can send me a script it would be helpful. i can pay u if u want 5qfb -8 — 4y