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

Can someone clarify why some scripts only work in Edit mode?

Asked by 6 years ago

I'm curious as to why some scripts only work in edit mode, and not when you publish it. I've had this problem before, and was given a solution, but I still don't understand why it does this. I've heard that it has something to do with the 'client' and the 'server' and stuff like that, but I don't truly understand what I keep doing wrong. Some justification is appreciated.

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local Char = player.Character
local Humanoid = Char:WaitForChild("Humanoid")



local animations = {1877306614,1877291193,01895620990}

local function Punch(plr)
local animation = Instance.new("Animation")
local picked = math.random(1, #animations)
animation.AnimationId = "http://roblox.com/asset/?id="..animations[picked]
local animTrack = Humanoid:LoadAnimation(animation)
animTrack:Play()
local dmgScript = script.DmgScript:Clone()
if picked == 1 then
    dmgScript.Parent = Char.RightHand
elseif picked == 2 then
    dmgScript.Parent = Char.LeftHand
elseif picked == 3 then
    dmgScript.Parent = Char.LeftFoot and Char.LeftLowerLeg
end
dmgScript.Disabled = false
wait(0.4)
dmgScript:Destroy()
end

Mouse.Button1Down:connect(function()
print("yup it worked")
Punch()
end)

This is inside a localscript inside of startergui ^^^

script.Parent.Touched:Connect(function(hit)
local char = hit.Parent
local hum = char:FindFirstChild("Humanoid")
if hum and char.Name ~= script.Parent.Parent.Name then
    hum.Health = hum.Health - script.Dmg.Value
    script.Disabled = true
    wait(0.5)
    script.Disabled = false
end
end)

This is inside a script inside of the script above ^^^

There is also an Int value inside of the normal script. ^^^

0
in edit mode, there is no difference between Server and Local. Zafirua 1348 — 6y
0
In edit mode, it can only simulate server and local while everything is still local. So server intended functions will not work in studio iiEpixnesss 0 — 6y
0
Thanks for the quick replies! So basically in edit mode, server scripts act like localscripts? McQuakyDuck 8 — 6y
0
not exactly, but whats happening is that on a normal on-line game, the "Server" wouldn't be local. In studio, the "Server" is local. Local scripts and regular scripts still act different, but its the local server that makes things sometimes work in studio but not in-game cruizer_snowman 117 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

Basically what happens is when you are testing in studio, everything there is local, meaning on your computer, even the server. When you play In-Game, the server is not local. You can view more on that if you go here: http://wiki.roblox.com/index.php/Client-Side_Scripting_and_Server-Side_Scripting

Second thing, make sure that any scripts you make are the right kind of script. When you use a local script, it means that whatever the local script does, only the player (you) can see. If it is a regular script, then everyone in the server can see what that script has done.

Third, If you use filtering enable (https://wiki.roblox.com/index.php?title=Experimental_Mode) and don't make the scripts comparable with it, it can cause a lot of errors. When using filtering enabled, you have to use functions for local scripts to communicate with the server. more on that here: https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events

those are the main reasons why when you test in studio it works, but when you test it in game it doesn't work.

Also, if you go to the "Test" tab of studio, the press "Start" it will simulate a online game. i suggest making it 2 players. don't touch local server.

I hope this helped, if you need any other help, feel free to contact me :)

0
Thanks for the clarification! I can't seem to figure out what's wrong with my script though. Sorry for being a complete noob at scripting, but I have no clue what part of my script isn't working the way its supposed to. Is it because it's in a LocalScript? Again, thanks. McQuakyDuck 8 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

In studio, when you run your game in 'Play Solo' or something, the server and the client are the same things so you can access client-side things that normally wouldn't be accessible by the server.

I can't think of an example at the moment, but will definitely edit my answer if I do.

Answer this question