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

Why is my ray cast gun with remote events not working?

Asked by 4 years ago

I have created a ray cast gun using the laser gun wiki and added reload functions, animations, ect. But recently I noticed that the enemies would be stuck on 0 or lower health and not dying. I searched it up and one thing said that the lag could be from the fact that it is all client sided and the server doesn't realize the zombie is dead. So I created a new script using remote events, a local script, and a server script, but when I try to shoot it the ray detects the player even though I set it to ignore the player. Please tell me what I did wrong and if I'm using remote events right, just started coding about 2 months ago. The local script is creating the ray and beam is created but no damage is dealt.

Local Script:

01--Variables---
02local tool = script.Parent
03local player = game:GetService("Players").LocalPlayer
04local firePart =  script.Parent:WaitForChild("firePart")
05local canShoot = true
06local UserInputService = game:GetService("UserInputService")
07local reloading = false
08local reloadNoti = player.PlayerGui.gunGui.Frame.reload
09local character = player.Character
10local HRP = character.HumanoidRootPart
11local light = script.Parent.firePart.SpotLight
12local ReplicatedStorage = game:GetService("ReplicatedStorage")
13local shotEvent = ReplicatedStorage.Events:WaitForChild("Shot")
14local ignoreList = {character}
15 
View all 96 lines...

Server:

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local hitSound = script.Hit
03local critSound = script.Crit
04local shotSound = script.Shot
05local reloadSound = script.Reloading
06 
07local shotEvent = ReplicatedStorage.Events:WaitForChild("Shot")
08 
09local function hasBeenShot(hit)
10    local rand = math.random(4)
11                if rand == 4 then
12                critSound:Play()
13                print("hit.Name")
14                print("critical")
15                hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 100
View all 23 lines...

Working old local script:

001--Variables---
002local tool = script.Parent
003local player = game:GetService("Players").LocalPlayer
004local firePart =  script.Parent:WaitForChild("firePart")
005local canShoot = true
006local UserInputService = game:GetService("UserInputService")
007local reloading = false
008local reloadNoti = player.PlayerGui.gunGui.Frame.reload
009local character = player.Character
010local HRP = character.HumanoidRootPart
011local light = script.Parent.firePart.SpotLight
012 
013--Sounds--
014local hitSound = script.Hit
015local critSound = script.Crit
View all 102 lines...
0
Try using hit.Parent.Humanoid:TakeDamage(100) mixgingengerina10 223 — 4y
0
I get "13:14:48.312 - Humanoid is not a valid member of Players 13:14:48.314 - Stack Begin 13:14:48.315 - Script 'Players.wildmanx20.Backpack.Magnum.ServerMain', Line 18 - function hasBeenShot 13:14:48.316 - Stack End". As the ray is detecting the player even though i told it not too in the local script Line 43 wildmanx20 35 — 4y
0
responding to mixginggengerina10 ^^ wildmanx20 35 — 4y
View all comments (3 more)
0
@Brandon1881 How would I use that? I replaced FindPartOnRay with it but i didn't work. i'm guessing I did it wrong. I got " 13:24:19.917 - Unable to cast value to Objects 13:24:19.918 - Stack Begin 13:24:19.919 - Script 'Players.wildmanx20.Backpack.Magnum.ClientMain', Line 43 13:24:19.920 - Stack End" wildmanx20 35 — 4y
0
Can you try and see what hit prints? mixgingengerina10 223 — 4y
0
It prints my username wildmanx20 35 — 4y

Answer this question