of     1   

radioactivated
#146521846Sunday, September 21, 2014 6:49 PM GMT

I put a script in a tool which can detect the object it hits and destroy it. This works perfectly in play solo but fails to work in online mode. Why is this?
VerifiedName
#146521925Sunday, September 21, 2014 6:50 PM GMT

things working in play solo and not in a server usually means you've accidently used a script instead of a local script or you've put the local script in the wrong place.
radioactivated
#146522000Sunday, September 21, 2014 6:51 PM GMT

The tool is derived from the basic LinkedSword, which means the sword script is a normal Script. By that logic, would changing the script to a local script affect the performance?
radioactivated
#146536313Sunday, September 21, 2014 9:58 PM GMT

I put the script in a localscript, and the collisions completely fail to register.
radioactivated
#146544753Sunday, September 21, 2014 11:49 PM GMT

bump
FreeScriptMaker
#146544938Sunday, September 21, 2014 11:51 PM GMT

Post the script.
radioactivated
#146547678Monday, September 22, 2014 12:29 AM GMT

Wall of text, it's in a local script: --Script originally from LinkedSword ("ClassicSword") r = game:service("RunService") local damage = 20 local slash_damage = 20 local lunge_damage = 20 sword = script.Parent.Handle Tool = script.Parent local SlashSound = Instance.new("Sound") SlashSound.SoundId = "rbxasset://sounds\\swordslash.wav" SlashSound.Parent = sword SlashSound.Volume = .7 local LungeSound = Instance.new("Sound") LungeSound.SoundId = "rbxasset://sounds\\swordlunge.wav" LungeSound.Parent = sword LungeSound.Volume = .6 local UnsheathSound = Instance.new("Sound") UnsheathSound.SoundId = "rbxasset://sounds\\unsheath.wav" UnsheathSound.Parent = sword UnsheathSound.Volume = 1 function blow(hit) if hit.Name== "BreakableCrate" then hit.Parent = nil script.Parent.Handle.CrateBreaking:Play() return end if hit.Name == "Vent" and hit:IsA("BasePart")then hit.Anchored = false hit:BreakJoints() end if (hit.Parent == nil) then return end -- happens when bullet hits sword local humanoid = hit.Parent:findFirstChild("Humanoid") local vCharacter = Tool.Parent local vPlayer = game.Players:playerFromCharacter(vCharacter) local hum = vCharacter:findFirstChild("Humanoid") -- non-nil if tool held by a character if humanoid~=nil and humanoid ~= hum and hum ~= nil then -- final check, make sure sword is in-hand local right_arm = vCharacter:FindFirstChild("Right Arm") if (right_arm ~= nil) then local joint = right_arm:FindFirstChild("RightGrip") if (joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword)) then tagHumanoid(humanoid, vPlayer) humanoid:TakeDamage(damage) wait(1) untagHumanoid(humanoid) end end end end function tagHumanoid(humanoid, player) local creator_tag = Instance.new("ObjectValue") creator_tag.Value = player creator_tag.Name = "creator" creator_tag.Parent = humanoid end function untagHumanoid(humanoid) if humanoid ~= nil then local tag = humanoid:findFirstChild("creator") if tag ~= nil then tag.Parent = nil end end end function attack() damage = slash_damage SlashSound:play() local anim = Instance.new("StringValue") anim.Name = "toolanim" anim.Value = "Slash" anim.Parent = Tool end function lunge() damage = lunge_damage LungeSound:play() local anim = Instance.new("StringValue") anim.Name = "toolanim" anim.Value = "Lunge" anim.Parent = Tool force = Instance.new("BodyVelocity") force.velocity = Vector3.new(0,10,0) --Tool.Parent.Torso.CFrame.lookVector * 80 force.Parent = Tool.Parent.Torso wait(.25) swordOut() wait(.25) force.Parent = nil wait(.5) swordUp() damage = slash_damage end function swordUp() Tool.GripForward = Vector3.new(-1,0,0) Tool.GripRight = Vector3.new(0,1,0) Tool.GripUp = Vector3.new(0,0,1) end function swordOut() Tool.GripForward = Vector3.new(0,0,1) Tool.GripRight = Vector3.new(0,-1,0) Tool.GripUp = Vector3.new(-1,0,0) end function swordAcross() -- parry end Tool.Enabled = true local last_attack = 0 function onActivated() if not Tool.Enabled then return end Tool.Enabled = false local character = Tool.Parent; local humanoid = character.Humanoid if humanoid == nil then print("Humanoid not found") return end t = r.Stepped:wait() if (t - last_attack < .2) then --lunge() attack() else attack() end last_attack = t --wait(.5) Tool.Enabled = true end function onEquipped(mouse) --UnsheathSound:play() mouse.Button1Down:connect(function() local connection = script.Parent.Handle.Touched:connect(blow) wait(0.5) connection:disconnect() end) end script.Parent.Activated:connect(onActivated) script.Parent.Equipped:connect(onEquipped) The idea is that the sword activates when the mouse button is down, so you can't just walk into something to break it.
systematicaddict
#146547918Monday, September 22, 2014 12:32 AM GMT

If you ever use LocalPlayer or :GetMouse() in the script that means it needs to be local to work in expected online mode.
radioactivated
#146583416Monday, September 22, 2014 7:22 PM GMT

I don't think the script references any of that (besides the mouse from the tool). (It's a modified LinkedSword script)
radioactivated
#146586388Monday, September 22, 2014 8:21 PM GMT

bump
radioactivated
#146588672Monday, September 22, 2014 8:55 PM GMT

bump
radioactivated
#146593275Monday, September 22, 2014 9:52 PM GMT

Ok, I changed the code to a simpler version (mainly due to the bad spaghetti-code in the regular sword script): print("Waiting for dependencies") repeat wait() until game.Workspace ~= nil repeat wait() until game.Players ~= nil print("done") Tool = script.Parent function slash(hit) --note: not a touched event call if hit.Name == "BreakableCrate" then print("Crate hit") end if hit.Parent ~= nil then if hit.Parent:FindFirstChild("Humanoid") ~= nil then print("Npc hit") end end end Tool.Equipped:connect(function(mouse) print("equipped") mouse.Button1Down:connect(function() print("mouse down") local connection = Tool.Handle.Touched:connect(slash) wait(1) connection:disconnect() end) end) This is mostly for debug, and is meant to trigger output messages when certain events happen. However, when testing in online mode, absolutely nothing triggers, not even the equipped event call. Why?
radioactivated
#146594527Monday, September 22, 2014 10:08 PM GMT

bump
systematicaddict
#146602604Monday, September 22, 2014 11:48 PM GMT

http://wiki.roblox.com/index.php?title=API:Class/Player/GetMouse "This item must be used in a LocalScript to work as expected online." Copy all of the script, delete the script object, insert a localscript in the same place, name it the same thing, then paste all the code into it. It should then work.

    of     1