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. ^^^
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 :)
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.