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

This doesn't work outside of studio/ It doesn't work in game, help me out?

Asked by 6 years ago
player = script.Parent.Parent.Parent.Parent.Character
playerinplayers = script.Parent.Parent.Parent.Parent
function AFK()
    player.Humanoid.MaxHealth = 10000000000
    player.Humanoid.Health = 10000000000
    player.Humanoid.WalkSpeed = 0
    playerinplayers.Backpack.Clean:Destroy()
    script.Parent.Visible = false
    script.Parent.Parent.AFKOff.Visible = true
end

script.Parent.MouseButton1Click:connect(AFK)

0
Please note that I have FilteringEnabled on rossthedestroyer9118 2 — 6y
0
Okay, a few questions. What outcome do you want? Are there any errors in the output? If there are, what are they? Also where is this script, inside a Gui or somewhere else? Troidit 253 — 6y
0
And is it a script or local script? Troidit 253 — 6y
0
it's not a localscript, inside a gui, i hooked up the parents because i know using game.Players.LocalPlayer.Characet won't work, so i figured that out, the outcome i want is to be an AFK button, in the game your character is always exposed to getting killed/damaged, and when people go afk i want them to be free from that, so the point of this is to take their clean tool away [sword basically] rossthedestroyer9118 2 — 6y
0
and restrict their movment [their walkspeed 0] rossthedestroyer9118 2 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

If your using filtering enabled, use a local script when having scripts in a gui. Second, some of the values your changing will only apear on the client, and not on the server. To get it to work properly, use a remote event. The following script will work with a remote event named "Afk" in ReplicatedStorage.

LocalScript inside the button:

local event = game:GetService('ReplicatedStorage'):WaitForChild('Afk')--get the event in ReplicatedStorage named Afk
local player = game.Players.LocalPlayer--get the player
function AFK()
    event:FireServer(player.Character)--give the server the player's character
    if player.Character then--check if character spawned in
        script.Parent.Visible = false
        script.Parent.Parent.AFKOff.Visible = true
    end
end

script.Parent.MouseButton1Click:connect(AFK)

Script inside ServerScriptService:

local event = game:GetService('ReplicatedStorage'):WaitForChild('Afk')--get the event in ReplicatedStorage named Afk
event.OnServerEvent:Connect(function(plr,character)--receive information from client
    if character then--make sure character is spawned in
        local hum = character:FindFirstChild("Humanoid")
        if hum then
            hum.MaxHealth = 1000000000--give the huge amount of helath
            hum.Health = 1000000000--same as above
            hum.WalkSpeed = 0--unable to move
            hum.JumpPower = 0--unable to jump
            local back = player:WaitForChild("Backpack")
            back:ClearAllChildren()--clear their backpack
        end
    end
end

Hope I could help, if you have any questions comment them below, and have a great day.

-REALTimothy0812

0
thank you so much! rossthedestroyer9118 2 — 6y
0
There is another script I'm having trouble with, how would I remove a model from the workspace for only that player? rossthedestroyer9118 2 — 6y
Ad

Answer this question