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

My script works in the Roblox Studio, but not in a local server. Why?

Asked by 6 years ago

Script in workspace:

local humanoid = game.Workspace.Speler.Humanoid
game.Players.PlayerAdded:connect(function(player)
    player = player
end)
humanoid.MaxHealth = 0
humanoid.Health = 0
humanoid.HealthChanged:connect(function(health)

    local players = game:GetService("Players")
humanoid.Parent.Head.Touched:connect(function(otherpart)
if otherpart.Name == "Handle" then
    local player = otherpart.Parent.Parent
    local replicatedstorage = game:GetService("ReplicatedStorage")
    local remote = Instance.new("RemoteEvent", replicatedstorage)
    remote:FireClient(player)

end
end)

end)

LocalScript in startergui:

local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

remote.OnClientEvent:connect(function()

    local health = game.Workspace.Speler.Humanoid.Health
    game.Workspace.Speler.Humanoid.MaxHealth = 100
    game.Workspace.Speler.Humanoid.Health = 100
end)

What i wanted to do was that if a player damages a humanoid, the damage would only be visible to the client. It did work fine with 1 player in Roblox Studio, but it doesn't work in the localserver.

0
The player with the sword does damage it in Roblox Studio, but in the localserver the humanoid get's no damage. That's what i meant kattenverzorger 23 — 6y
0
who is "Speler"? Speler doesnt exist in real servers cabbler 1942 — 6y
0
Speler is a model in workspace kattenverzorger 23 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
local humanoid = game.Workspace.Speler.Humanoid
game.Players.PlayerAdded:connect(function(player)
    player = player
end)
humanoid.MaxHealth = 0
humanoid.Health = 0
humanoid.HealthChanged:connect(function(health)

    local players = game:GetService("Players")
humanoid.Parent.Head.Touched:connect(function(otherpart)
if otherpart.Name == "Handle" then
    local player = otherpart.Parent.Parent.Parent
    print(otherpart.Parent.Parent.Parent.Name)
    local replicatedstorage = game:GetService("ReplicatedStorage")
    local remote = Instance.new("RemoteEvent", replicatedstorage)
    remote:FireClient(player)

end
end)

end)

At line 13, the part where i wanted to print the otherpart.Parent.Parent.Parent. It gaves in the output 'workspace'. Tht item is in the starterpack, backpack when the game starts. Why does it print workspace?

0
I guess the otherPart is a Tool, which happens to be in your Character folder in Workspace when equipped. YourHandle.YourTool.YourCharacter.Workspace.Name == Workspace User#17685 0 — 6y
Ad

Answer this question